Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#将文件夹添加到资源?_C#_Resources_Directory - Fatal编程技术网

c#将文件夹添加到资源?

c#将文件夹添加到资源?,c#,resources,directory,C#,Resources,Directory,在我的项目中,我想将几个包含不同文件的文件夹添加到项目属性资源,但我发现无法将文件夹添加到资源,这是我真正需要的方式 那么,是否有任何可能的方法可以将文件夹添加到项目属性资源中?在VisualStudio中,我只发现添加现有文件、添加新字符串等等 提前感谢阅读我的问题的所有人。您可以将文件夹压缩到ZIP文件中,添加文件,然后在运行时解压缩。 正在使用System.IO.Compression string startPath = @"c:\example\start";//fol

在我的项目中,我想将几个包含不同文件的文件夹添加到
项目属性资源
,但我发现无法将文件夹添加到资源,这是我真正需要的方式

那么,是否有任何可能的方法可以将文件夹添加到
项目属性资源中
?在VisualStudio中,我只发现添加现有文件、添加新字符串等等


提前感谢阅读我的问题的所有人。

您可以将文件夹压缩到ZIP文件中,添加文件,然后在运行时解压缩。 正在使用System.IO.Compression

        string startPath = @"c:\example\start";//folder to add
        string zipPath = @"c:\example\result.zip";
        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);
要在每次更新时执行此操作,请执行类似于创建删除设置的操作,在分发时将其设置为true,然后:

 private void shouldExtract()
    {
        if (MyProject.Properties.Settings.Default.DeleteExtractionFolder == true)
        {
            if (Directory.Exists(myExtractionDirectory))
            {
                Directory.Delete(myExtractionDirectory);
                //unzip
                MyProject.Properties.Settings.Default.DeleteExtractionFolder = false;
            }
        }
    }

为什么“无法将文件夹添加到资源”?@第一步,我没有找到将文件夹添加到资源的选项,在“属性资源”中,我只找到了添加字符串、图标、图像、文本文件和现有文件,但找不到添加文件夹的方法。谢谢,我会试试看。这是否意味着每次我想使用我的程序时都必须解压缩zip文件?有没有办法只做一次,然后我就不需要提取了?嗯,是和否。例如,你可以在程序的开头检查文件夹是否存在。如果没有,则提取。这会起作用,但你需要确保将来的更新会被删除或重写文件夹。有很多方法可以在你需要更新(文本文件、数据库、设置等)时挂上“删除/覆盖”标志。这可能是最简单的方法,假设你甚至需要更新文件夹。好的,好主意!我试试看。