Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取保存在解决方案中的Excel模板的副本_C#_Visual Studio_Projects And Solutions - Fatal编程技术网

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);