[英]How do I get something from inside a project to a directory? (C#)
Here is my code:这是我的代码:
using System;
namespace msoApplier
{
class Program
{
static void Main()
{
string targetPath = @"C:\Program Files (x86)\MyProgram";
System.IO.Directory.CreateDirectory(targetPath);
System.IO.File.Copy("ExampleProgram.exe", targetPath);
Console.ReadKey();
}
}
}
ExampleProgram.exe is in the same folder as Program.cs. ExampleProgram.exe 与 Program.cs 位于同一文件夹中。 Is there anything I can do?
有什么我可以做的吗? I don't want ExampleProgram.exe to be seperate from the program, I want it to be inside the program, and then copied to that place.
我不希望 ExampleProgram.exe 与程序分开,我希望它在程序内部,然后复制到那个地方。
How about to get the Path of your executing exe?如何获取执行 exe 的路径? Then you could spezify the copy process with the whole Path?
那么你可以用整个路径指定复制过程吗?
eg.:例如。:
string SourceDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
string SourceFile = SourceDir + "\ExampleProgram.exe";
System.IO.File.Copy(SourceFile , targetPath);
Haven't tested it, because I'm not at Work.没有测试它,因为我不在工作。
Kind Regards亲切的问候
It sounds like you want to store ExampleProgram.exe inside the program that your source code produces.听起来您想将 ExampleProgram.exe 存储在源代码生成的程序中。 If that is the case, you can store that ExampleProgram.exe as a resource within your program then read the resource and store it at the location of your choice.
如果是这种情况,您可以将该 ExampleProgram.exe 作为资源存储在程序中,然后读取该资源并将其存储在您选择的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.