Encryptfile (advapi32)
Last changed: -37.160.138.42

.
Summary
EncryptFile turns on file level system encryption for a specific file or folder

C# Signature:

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EncryptFile(string filename);

VB Signature:

Declare Function EncryptFile Lib "advapi32.dll" (TODO) As TODO

User-Defined Types:

None.

Notes:

This requires that Windows supports Encrypted File System (EFS) which is only

supported under NTFS.

Tips & Tricks:

Please add some!

C# Sample Code:

[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError=true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool EncryptFile(string filename);

string FileName = "C:\PATH\TO\YOUR\FILE";
if(EncryptFile(FileName)){
   //File encrypted
} else{
   throw new Exception("Encryption failed.");
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation
Encryptfile on MSDN