C# 获取保存在解决方案中的Excel模板的副本
我有这样的解决方案结构: 我想复制此模板,然后将其保存到网络驱动器。使用C# 获取保存在解决方案中的Excel模板的副本,c#,visual-studio,projects-and-solutions,C#,Visual Studio,Projects And Solutions,我有这样的解决方案结构: 我想复制此模板,然后将其保存到网络驱动器。使用System.IO我以前曾使用此代码复制文件: string templateFilePath = @"\\blah\blah\blah\blah\Temp.xlsx"; //<<<< X string exportFilePath = @"\\blah\blah\blah\blah\Results.xlsx"; File.Copy(templateFilePath, exportFilePat
System.IO
我以前曾使用此代码复制文件:
string templateFilePath = @"\\blah\blah\blah\blah\Temp.xlsx"; //<<<< X
string exportFilePath = @"\\blah\blah\blah\blah\Results.xlsx";
File.Copy(templateFilePath, exportFilePath, true);
string templateFilePath=@“\\blah\blah\blah\blah\Temp.xlsx”// 您需要指定文件的完整路径或与可执行文件运行位置相关的相对路径。因此,您可以设置targetFileName=“。\template.xlsx
获取文件的另一种方法是在文件的属性中标记生成操作并将其设置为Embedded Resource。然后使用以下代码获取流。不确定流是否对您有帮助
Assembly asm = Assembly.GetExecutingAssembly();
string file = string.Format("{0}.Template.xlsx", asm.GetName().Name);
var ms = new MemoryStream();
Stream fileStream = asm.GetManifestResourceStream(file);