标签:
解决方案
Serializer
启动项目
WPFApplication
获取正在运行程序的完整路径
//结果 "D:\\用户目录\\我的文档\\Visual Studio 2013\\Projects\\Serializer\\WPFApplication\\bin\\Debug\\WPFApplication.exe" string a = System.Reflection.Assembly.GetEntryAssembly().Location;
//结果 ‘\\‘ char c = System.IO.Path.DirectorySeparatorChar; //结果 76 int b =System.Reflection.Assembly.GetEntryAssembly().Location.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
获取运行程序所在文件夹的路径 //结果 "D:\\用户目录\\我的文档\\Visual Studio 2013\\Projects\\Serializer\\WPFApplication\\bin\\Debug" string appDir = System.IO.Path.Combine(System.Reflection.Assembly.GetEntryAssembly().Location.Substring(0, System.Reflection.Assembly.GetEntryAssembly().Location.LastIndexOf(System.IO.Path.DirectorySeparatorChar)));
拼接文件夹 //结果 "D:\\用户目录\\我的文档\\Visual Studio 2013\\Projects\\Serializer\\WPFApplication\\bin\\Update" string updateFileDir = System.IO.Path.Combine(System.IO.Path.Combine(appDir.Substring(0, appDir.LastIndexOf(System.IO.Path.DirectorySeparatorChar))), "Update");
获得运行程序的名字 去掉exe //结果 "WPFApplication" string _callExeName = System.Reflection.Assembly.GetEntryAssembly().Location.Substring(System.Reflection.Assembly.GetEntryAssembly().Location.LastIndexOf(System.IO.Path.DirectorySeparatorChar) + 1).Replace(".exe", ""); }
标签:
原文地址:http://www.cnblogs.com/zscmj/p/4609081.html