在我的项目中,我想将包含不同文件的几个文件夹添加到Project-Properties-Resources
,但我发现我无法向资源添加文件夹,这是我真正需要的方式。
那么,有没有办法可以将文件夹添加到Project-Properties-Resources
?在visual studio中,我只找到了Add Existing File,Add New String等等。
提前感谢所有阅读我问题的人。
答案 0 :(得分:3)
将文件夹压缩为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;
}
}
}
Adding a whole folder (with subfolders) as embedded resource?