我如何获取应用程序的文件名? [英] how can i get the filename of my application?

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

问题描述

大家好
我想在文件名更改时获取文件名(以使应用程序自身复制).

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 property Assembly.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 example Application.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


查找程序集名称的一种方法是使用 Assembly.GetEntryAssembly [
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屋!

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