Bingjie Han Bingjie Han - 1 year ago 136
C# Question

c# add folders to resources?

In my project, I want to add several folders containing different files to

, but I found that I could't add folders to resources, which is the way I really need.

So, is there any possible way that I can add folders to
? In visual studio, I only found Add Existing File, Add New String and so on.

Thanks in advance to anyone who read my question.

Answer Source

You compress the folders into ZIP files, add the file, then decompress at runtime. using System.IO.Compression....

        string startPath = @"c:\example\start";//folder to add
        string zipPath = @"c:\example\";
        ZipFile.CreateFromDirectory(startPath, zipPath, CompressionLevel.Fastest, true);
        //add the ZIP file you just created to your resources

        //Then, on startup, extract the zip to a folder you control
        string extractPath = @"c:\example\extract";
        ZipFile.ExtractToDirectory(zipPath, extractPath);

To do this once per update, do something like create a setting for delete, set it to true on distribution, then:

 private void shouldExtract()
        if (MyProject.Properties.Settings.Default.DeleteExtractionFolder == true)
            if (Directory.Exists(myExtractionDirectory))
                MyProject.Properties.Settings.Default.DeleteExtractionFolder = false;

Adding a whole folder (with subfolders) as embedded resource?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download