首页 > 其他 > 详细

获取项目相关路径方法

时间:2015-06-29 23:42:39      阅读:222      评论:0      收藏:0      [点我收藏+]
解决方案
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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!