如何获取应用程序的路径(不APP.EXE)? [英] How to get the path of app(without app.exe)?

查看:283
本文介绍了如何获取应用程序的路径(不APP.EXE)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到我的应用程序的路径,如:\\\\ \\\\ PROGRAMFILES对myApp,我尝试使用以下code:

 
字符串路径= System.Reflection.Assembly.GetExecutingAssembly()的GetName()codeBase的。;

但在最后返回具有路径\\\\ MyApp.exe的。

我也试过:

 
字符串路径= System.IO.Directory.GetCurrentDirectory();

但它抛出一个NotSupportedException异常。

有什么办法在年底拿到的路径下的.exe?


解决方案

 路径= System.IO.Path.GetDirectoryName(路径);

I want to get the path of my app like: "\\ProgramFiles\\myApp", I try to use the following code:


string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;

But it returns a path which has "\\myapp.exe" at the end.

I also tried:


string path = System.IO.Directory.GetCurrentDirectory();

But it throws an "NotSupportedException".

Is there any way to get a path without .exe at the end?

解决方案

path = System.IO.Path.GetDirectoryName( path );

这篇关于如何获取应用程序的路径(不APP.EXE)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆