///
/// 获取当然exe文件所在的路径
///
///
public static string GetAbsolutePath()
{
string FolderPath = string.Empty;
try
{
string strCodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
int n = strCodeBase.LastIndexOf('/');
if (n > 8)
{
FolderPath = strCodeBase.Substring(8, n - 8); // 8是 file:/// 的长度
}
else
{
FolderPath = ".";
}
}
catch
{
FolderPath = ".";
}
return FolderPath;
}
String path = "我是绝对路径下面的txt:" + Application.StartupPath.ToString() + "\\我是文本.text
Application.StartupPath 指的是:你程序下面的\bin\Debug 同一级的目下的内容!
注意:using System.Windows.Forms; 不引入不Application 就用不了!
希望对LZ有帮助!
AppDomain.CurrentDomain.BaseDirectory
获取当前应用程序域的基目录
如果要获取应用程序根目录下的文件路径可以这样写:
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory
, "test.txt");
用相对路径吧
string Path="bin\a.txt";