【发布时间】:2015-12-09 19:33:34
【问题描述】:
我创建了一个Form Application 并尝试获取可执行路径,结果发现:
System.Reflection.Assembly.GetExecutingAssembly().Location;
System.IO.Path.GetDirectoryName;
但是当我输入我的代码时,我遇到了很多错误。
这是我的代码:
namespace inst
{
public class Program
{
System.Reflection.Assembly.GetExecutingAssembly().Location;
System.IO.Path.GetDirectoryName;
[STAThread]
static void Main()
{
}
}
它就在我放置的地方吗?我想使用该位置来查找一个文本文件,以便能够更改,如下所示:
private void Form1_Load(object sender, EventArgs e)
{
this.Text = File.ReadLines(Program.Path)
.First(x => x.StartsWith("Title=\""))
.Split(new[] { '=', '"' }, StringSplitOptions.RemoveEmptyEntries)[1];
}
Path 是文件文本的位置。
所以我想获取文件test.txt 所在位置的可执行文件的位置,将位置放在变量中并在form1 和form2 中使用该变量,就我而言
【问题讨论】:
标签: c#