申请路径 [英] Application path
问题描述
我有一个应用程序,其中我需要exe
文件路径的信息。应用程序必须在紧凑和完整的框架上运行,并且在
Internet上我发现这个代码片段应该有效(至少在CF上):
" Path。 GetDirectoryName(Assembly.GetExecutingAssemb ly()。GetName()。CodeBase)"
它在Compact Framework上非常好用,我得到:
" \Program Files \ My Company"
但在完整框架上,file:结果路径在
前面应用反斜杠,如下所示:
" file:\ C:\Program files \ My Company"
有什么问题以及如何做到这一点(这对CF和/或
和FF都有效?
谢谢,
Ole
Hi,
I have an application in which I need information of the path to the exe
file. The application must run on both compact and full framework and on the
Internet I found this code snip that should work (on the CF at least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().CodeBase)"
It works very fine on Compact Framework where I get:
"\Program Files\My Company"
But on the full framework a "file:" and a backslash is applied in front of
the resulting path as in:
"file:\C:\Program files\My Company"
What is wrong and how is the correct way to do it( that will work on both CF
and FF ?
Thanks,
Ole
推荐答案
你好Ole,
我的避风港没有使用CompactFramework进行任何练习。
但是如果你想获得执行二进制的路径,那么你可以使用:
Application.ExecutablePath
或
Application.StartupPath - 获取其目录
HTH
Marcin
Hi Ole,
I haven''t got any practise with CompactFramework.
But if you want to get path of executing binary then you can use:
Application.ExecutablePath
or
Application.StartupPath - to get its directory
HTH
Marcin
我有一个应用程序,我需要有关exe
文件路径的信息。应用程序必须在紧凑和完整的框架上运行,并且在
上互联网我发现这个代码剪辑应该有效(至少在CF上):
Path.GetDirectoryName(汇编。 GetExecutingAssemb ly()。GetName()。CodeBase)"
我在Compact Framework上工作得非常好:
" \ Program Files \ My Company"
但在完整框架上,文件:并且在结果路径前面应用反斜杠,如下所示:
" file:\ C:\Program files \ My Company"
有什么问题如何做到这一点(这对CF
和FF都有效?
谢谢,
Ole
Hi,
I have an application in which I need information of the path to the exe
file. The application must run on both compact and full framework and on the
Internet I found this code snip that should work (on the CF at least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().CodeBase)"
It works very fine on Compact Framework where I get:
"\Program Files\My Company"
But on the full framework a "file:" and a backslash is applied in front of
the resulting path as in:
"file:\C:\Program files\My Company"
What is wrong and how is the correct way to do it( that will work on both CF
and FF ?
Thanks,
Ole
对于完整框架,你必须使用
System.Reflection.Assembly.GetEntryAssembly()。位置。在运行时你
可以检测框架版本(System.Environment.Version)并在它们之间切换
。
祝你好运,
Sergey Bogdanov
ORC写道:
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.Version) and switch
between them.
Best regards,
Sergey Bogdanov
ORC wrote:
我有一个应用程序,其中我需要exe的路径信息应用程序必须在紧凑和完整的框架上运行,并且在互联网上我发现这个代码片段应该有效(至少在CF上):
Path.GetDirectoryName(汇编。 GetExecutingAssemb ly()。GetName() .CodeBase)
它在Compact Framework上运行得非常好,我得到:
" \ Program Files \ My Company"
但是在完整框架a文件:并且在结果路径前面应用反斜杠,如下所示:
" file:\ C:\Program files \ My Company"
有什么问题如何做到这一点(这对CF
和FF都有效?
谢谢,
Ole
Hi,
I have an application in which I need information of the path to the exe
file. The application must run on both compact and full framework and on the
Internet I found this code snip that should work (on the CF at least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().CodeBase)"
It works very fine on Compact Framework where I get:
"\Program Files\My Company"
But on the full framework a "file:" and a backslash is applied in front of
the resulting path as in:
"file:\C:\Program files\My Company"
What is wrong and how is the correct way to do it( that will work on both CF
and FF ?
Thanks,
Ole
在运行时无法检查操作系统版本,然后使用
适当的路径检测代码行,因为编译器没有/ >
CF中GetEntryAssembly的定义。其他一些想法?
谢谢,
Ole
" Sergey Bogdanov" ;< se ************* @ gmail.com>在留言中写道
新闻:%2 ************* *** @ TK2MSFTNGP15.phx.gbl ...
It is not possible to check OS version during runtime and then use the
appropiate path detect code line because the compiler doesn''t have a
definition for GetEntryAssembly in CF. Some other idea?
Thanks,
Ole
"Sergey Bogdanov" <se*************@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
对于完整框架,您必须使用
System.Reflection.Assembly.GetEntryAssembly()。位置。在运行时,您需要/>可以检测框架版本(System.Environment.Version)并在它们之间切换。
最好问候,谢尔盖·波格丹诺夫
ORC写道:
Also for a Full Framework you must use
System.Reflection.Assembly.GetEntryAssembly().Loca tion. At runtime you
can detect framework version (System.Environment.Version) and switch
between them.
Best regards,
Sergey Bogdanov
ORC wrote:
我有一个应用程序,其中我需要有关路径的信息exe
文件。应用程序必须在紧凑和完整框架上运行,并且在
互联网上我发现这个代码片段应该起作用(至少在CF上):
" Path.GetDirectoryName(Assembly。 GetExecutingAssemb ly()。GetName()。CodeBase)"
它在Compact Framework上非常好用,我得到:
" \ Program Files \ My Company"
>但在完整框架上,文件:并且在结果路径的前面
中应用反斜杠,如:
" file:\ C:\ Program Files \ My Company"
有什么问题以及如何正确地做到这一点(这将适用于
CF和FF?
谢谢,
Ole
Hi,
I have an application in which I need information of the path to the exe
file. The application must run on both compact and full framework and on the Internet I found this code snip that should work (on the CF at least):
"Path.GetDirectoryName(Assembly.GetExecutingAssemb ly().GetName().CodeBase)"
It works very fine on Compact Framework where I get:
"\Program Files\My Company"
But on the full framework a "file:" and a backslash is applied in front of the resulting path as in:
"file:\C:\Program files\My Company"
What is wrong and how is the correct way to do it( that will work on both CF and FF ?
Thanks,
Ole
这篇关于申请路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!