c# 将文件夹添加到资源?
c# add folders to resources?
在我的项目中,我想将几个包含不同文件的文件夹添加到Project-Properties-Resources
,但我发现我无法将文件夹添加到资源中,这才是我真正需要的方式。
那么,有什么方法可以将文件夹添加到 Project-Properties-Resources
?在visual studio中,我只找到了Add Existing File,Add New String等等。
提前感谢阅读我的问题的任何人。
您将文件夹压缩成 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?
在我的项目中,我想将几个包含不同文件的文件夹添加到Project-Properties-Resources
,但我发现我无法将文件夹添加到资源中,这才是我真正需要的方式。
那么,有什么方法可以将文件夹添加到 Project-Properties-Resources
?在visual studio中,我只找到了Add Existing File,Add New String等等。
提前感谢阅读我的问题的任何人。
您将文件夹压缩成 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?