可执行路径 [英] Path to executable
本文介绍了可执行路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们,
如何在运行时获取当前可执行文件的路径?我认为VB6
相当于App.Path。
感谢您的帮助。
FireStarter
Guys,
How can I get the path to the current executable at run time? I think the VB6
equivalent is App.Path.
Thanks for your help.
FireStarter
推荐答案
您好,
您可以使用System.Reflection.Assembly.GetExecutingAssembly.Lo cation 。
希望这有帮助
Chris Taylor
FireStarter < EM *** @ server.com>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...
Hi,
You can use System.Reflection.Assembly.GetExecutingAssembly.Lo cation.
Hope this helps
Chris Taylor
"FireStarter" <em***@server.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
伙计们,
如何在运行时获取当前可执行文件的路径?我认为
VB6等价物是App.Path。
感谢您的帮助。
FireStarter
Guys,
How can I get the path to the current executable at run time? I think the VB6 equivalent is App.Path.
Thanks for your help.
FireStarter
也许我也应该解释一下我想做什么。
我有一个.dll,我想为它构建一个XML配置文件。在运行时
我将转到配置文件并从中获取一些设置(数据库
连接字符串)。
我''使用XmlDocument并尝试加载配置文件:
XmlDocument appConfig = new XmlDocument();
appConfig.Load(" filename.config" );
问题是,当我运行程序时,它会在winnt \system32中查找
filename.config。
我试过使用System.IO.Directory.GetCurrentDirectory(),但是返回
winnt \ system32,也是(?!)。
是什么给出的?我如何重写上面代码的第2行,以便它在.dll的同一文件夹中读取文件
?
我希望这是有道理的。
谢谢。 FireStarter。
Maybe I should also explain what I want to do.
I have a .dll and I want to build an XML configuration file for it. At run time
I will go to the configuration file and get some settings out of it (database
connection string).
I''m using an XmlDocument and try loading the config file with:
XmlDocument appConfig = new XmlDocument();
appConfig.Load("filename.config");
The problem is, when I run the the program it is looking in winnt\system32 for
filename.config.
I have tried to use System.IO.Directory.GetCurrentDirectory(), but that returns
winnt\system32, also (?!).
What gives? how can i rewrite line 2 of the code above so that it reads a file
in the same folder with the .dll?
I hope this makes sense.
Thanks. FireStarter.
Chris,
感谢您的快速回复。
我在ASP.NET应用程序中使用dll,它返回:
" c:\ winnt \ microsoft.net \ framework \v1.1.4322 \ tempor ary asp.net
files\ecommerce\c080a7de\d2993907\assembly\dl2\eea f87ff \
50714524_a378c301 \ ecommbizobjects.dll \" ;
唉!当然,找不到我的配置文件:)
Chris Taylor写道:
Chris,
Thanks for the prompt response.
When I use the dll in an ASP.NET application, that returns:
"c:\winnt\microsoft.net\framework\v1.1.4322\tempor ary asp.net
files\ecommerce\c080a7de\d2993907\assembly\dl2\2ea f87ff\
50714524_a378c301\ecommbizobjects.dll\"
Ugh! Of course, my configuration file is not found :)
Chris Taylor wrote:
你可以使用System。 Reflection.Assembly.GetExecutingAssembly.Lo cation。
Hi,
You can use System.Reflection.Assembly.GetExecutingAssembly.Lo cation.
这篇关于可执行路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文