Powered by Blogger.

Sunday, February 23, 2014

Encrypt and Decrypt a file in C#.Net

In this post we will discuss about how we can encrypt or decrypt a file in C#.Net. You can also check my previous posts on CLR in C#.Net, Exception handling in C#.Net and Concurrent Collections in .NET 4.0.

Also check out:

- Bind gridview using datareader in asp.net

- Get all tables and stored procedures in sql server 2008

- Create generics lists in C#.Net

Encrypt will not allow other 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";

Decrypt File:

string fileToEncrypt = @"C:\AspDotNetHelp";

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