正在从资源复制文件
本文关键字:复制 文件 资源 | 更新日期: 2023-09-27 18:20:02
在我的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);
}
}