EnjoySharePoint YouTube Channel

Encrypt and Decrypt a file in C#.Net


In this post, we will discuss how we can encrypt or decrypt a file in C#.Net.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

You can also check my previous posts on

Delegates in C#.Net,

Exception handling in C#.Net 

Concurrent Collections in .NET 4.0.

Encrypt will not allow another user to open and read the file.

To work with files and directory, Microsoft provides System.IO namespace. Here we will use the inbuilt File class to encrypt or decrypt the file.

Encrypt File:

string fileToEncrypt = @”C:\AspDotNetHelp”;
File.Encrypt(fileToEncrypt);

Decrypt File:

string fileToEncrypt = @”C:\AspDotNetHelp”;
File.Decrypt(fileToEncrypt);

You can also check my previous article on how to delete a file in C#.Net.

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →