C#添加文件夹资源? [英] c# add folders to resources?
问题描述
在我的项目中,我想将几个包含不同文件的文件夹添加到 Project-Properties-Resources
,但是我发现无法将文件夹添加到资源中,这是我真正需要的方式
In my project, I want to add several folders containing different files to Project-Properties-Resources
, but I found that I could't add folders to resources, which is the way I really need.
那么,有什么方法可以将文件夹添加到 Project-Properties-Resources
?在Visual Studio中,我只找到添加现有文件",添加新字符串"等等.
So, is there any possible way that I can add folders to Project-Properties-Resources
? In visual studio, I only found Add Existing File, Add New String and so on.
在此先感谢所有阅读我的问题的人.
Thanks in advance to anyone who read my question.
推荐答案
您将文件夹压缩为ZIP文件,添加文件,然后在运行时解压缩.使用System.IO.Compression ....
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\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,然后:
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))
{
Directory.Delete(myExtractionDirectory);
//unzip
MyProject.Properties.Settings.Default.DeleteExtractionFolder = false;
}
}
}
这篇关于C#添加文件夹资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!