Has anyone created a new directory from C# with Encrypting File System switched on?
Additionally any information on doing this from an install would be helpful too.
To create a new directory we will be using the mkdir() command. Note that the given code will work only for windows compiler.
The mkdir function creates a new, empty directory with name filename . The argument mode specifies the file permissions for the new directory file.
Open the terminal application in Linux. The mkdir command is is used to create new directories or folders. Say you need to create a folder name dir1 in Linux, type: mkdir dir1.
Creating an encrypted directory would be a two step process - create it using Directory.CreateDirectory and then encrypt it using the Win32 function EncryptFile. Sample code -
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace EncryptDir
{
public class Sample
{
DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool EncryptFile(string filename);
public static void Main ()
{
Directory.CreateDirectory("MyEncryptedDirectory");
EncryptFile("MyEncryptedDirectory");
}
}
References:
EncryptFile Function @ MSDN
Handling encrypted files and directories @ MSDN
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With