好吧,在我的 C# 项目中,我向资源添加了一个 .xml 文件,我希望将其从中提取/复制到应用程序路径,我正在尝试这样做:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);//Declaration of the apppath
File.Copy(appPath, Properties.Resources.config);//process for copy
但是不工作:/,我怎样才能做我想做的事?
最佳答案
确保资源上的构建操作设置为“嵌入资源”。
var assembly = Assembly.GetExecutingAssembly();
// See what resources are in the assembly (remove from the final code)
foreach (var name in assembly.GetManifestResourceNames()) {
Console.Writeline("'{0}'", name);
}
using (var inputStream = assembly.GetManifestResourceStream(resourcePath)) {
using( var outStream = File.OpenWrite(copyToPath)) {
input.CopyTo(outStream);
}
}
关于c# - 从资源复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8798065/