我如何获取应用程序的文件名? [英] how can i get the filename of my application?
本文介绍了我如何获取应用程序的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我想在文件名更改时获取文件名(以使应用程序自身复制).
Hi all
I want to get the filename whenever it change(to make my application copy itself).
推荐答案
Try:
Try:
Dim fileName As String = Application.ExecutablePath
除了Mika的好回答:当您获得程序集实例时,请使用属性Assembly.Location
;.它将为您提供Give程序集的主要可执行文件的文件名:
http://msdn.microsoft.com/en-us/library/system. Reflection.assembly.location.aspx [ ^ ].
我还要指出,这是一个很好的方法,没有其他方法存在的问题.例如,Application.ExecutablePath
仅适用于Forms应用程序.其他一些方法取决于应用程序的托管方式,并为Windows Services或在IDE托管的应用程序中给出错误或无用的结果.
-SA
In addition to the good answer by Mika: when you got the instance of an assembly, use the propertyAssembly.Location
; it will give you the file name of the main executable of the give assembly:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.location.aspx[^].
I would also note that this is a good method free from problems other method have; for exampleApplication.ExecutablePath
is only good for Forms applications; some other methods depends on how the application is hosted and give wrong or useless results for Windows Services or in case of application hosted by the IDE.
—SA
查找程序集名称的一种方法是使用 ^ ]或 ^ ],具体取决于您是否想知道该exe或正在执行的程序集.
One way to find out the assembly name is to use Assembly.GetExecutingAssembly[^] or Assembly.GetEntryAssembly[^] depending if you want to know the exe or the executing assembly.
这篇关于我如何获取应用程序的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文