怎样用c#打开根目录下(就是与该c#的exe程序同一个目录下,并不用确定具体的路径)的文件。

最好能有实例说明

AppDomain.CurrentDomain.BaseDirectory
Application.StartupPath
都可以打开根目录的,编程时,是打开到你的工程/bin/debug下的,当你打包发布后就是与exe程序同一目录下的
温馨提示:内容为网友见解,仅供参考
第1个回答  2010-12-21
C#中简单的用
System.Diagnostics.Process.Start("explorer.exe", System.IO.Directory.GetCurrentDirectory());
复杂的调用window API shell32.dll,这个得查查MSDN了本回答被提问者采纳
第2个回答  2010-12-21
使用 Application.StartupPath
string skinFloder = Application.StartupPath + "*.exe";
if (Directory.Exists(skinFloder))
{
MessageBox.Show("*.exe正在运行");
}
else
{
MessageBox.Show("不存在*.exe文件");
return;
}
第3个回答  2010-12-21
string filename;
filename ="email_log.log";
if (File.Exists(filename))
{
StreamWriter sw = new StreamWriter(filename, true);
sw.WriteLine("");
sw.WriteLine("日志: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "============================================================================");
sw.WriteLine(content);
sw.Close();
return;
}

像这样子的,什么路径也不要写就对了
第4个回答  2010-12-21
str += "\r\n" + System.Windows.Forms.Application.ExecutablePath;
结果为:
D:\1\bin\Debug\路径测试.EXE
相似回答