http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105392230e54f73b6cd0d3027fa3cf1fd5790801013db2e5703f170fd7c27e7001d8131ab5e4732f77552fe68cc8895ddccbd77373dc7a742f0b873105a31fb8bf3532b126c34de8df0e91bfba25e2a4c5a0dc4352ba44737e9780814d7010dd1cfa033093b1e83f022e16ad9d41728b2e&p=86759a46d7c159e50be296395b5697&newp=8774c71985cc43b708e2977f0f5785231610db2151d6d3156b82c825d7331b001c3bbfb42324140ed7ce766603ad425eebf23273300421a3dda5c91d9fb4c5747990&user=baidu&fm=sc&query=C%23winform%B4%FA%B4a%D7x%C8%A1%D6%B8%B6%A8%CE%C4%BC%FE&qid=93cca5ce00011011&p1=6
winform使用相对路径读取C#中文件的方法,实例分析了文件的技巧与实际应用,需要的朋友可以参考下
本文实例讲述了winform使用相对路径读取
方法一:由于生成的exe文件
FileInfo file = new FileInfo(fileName);
string fullName = file.FullName;
方法二:获取exe文件名,形成全路径
string fullName = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\"));
fullName = fullName.Substring(0, fullName.LastIndexOf("\\")) + "\\" + haarXmlPath;
另一种方式:
/// 获取应用程序根路径
/// </summary>
private static string GetApplicationPath()
{
string path = Application.StartupPath;
//string path=AppDomain.CurrentDomain.BaseDirectory; //另一种获取方式
string folderName = String.Empty;
while (folderName.ToLower() != "bin")
{
path = path.Substring(0, path.LastIndexOf("\\"));
folderName = path.Substring(path.LastIndexOf("\\") + 1);
}
return path.Substring(0, path.LastIndexOf("\\") + 1);
}
希望本文所述对大家的C#程序设计有所帮助