zoukankan      html  css  js  c++  java
  • 获取项目相关路径方法

    解决方案
    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", ""); }

    作者:zscmj
    出处:http://www.cnblogs.com/zscmj/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    剑指offer_11:二进制中1的个数
    剑指offer_10:矩形覆盖
    spring mvc 访问静态资源
    spring context:component-scan ex
    spring aop配置未生效
    415 Unsupported Media Type
    spring mvc 接收List对象入参
    JIRA甘特图
    JIRA的工时
    JIRA导出工作日志到Excel
  • 原文地址:https://www.cnblogs.com/zscmj/p/4609081.html
Copyright © 2011-2022 走看看