Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a new directory from C# with Encrypting File System switched on

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.

like image 803
forest Avatar asked May 24 '11 14:05

forest


People also ask

How do you create a directory in C?

To create a new directory we will be using the mkdir() command. Note that the given code will work only for windows compiler.

What is mkdir in C?

The mkdir function creates a new, empty directory with name filename . The argument mode specifies the file permissions for the new directory file.

How do you create a new directory in terminal?

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.


1 Answers

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

like image 121
DotThoughts Avatar answered Oct 04 '22 11:10

DotThoughts