应用程序路径不受支持 [英] application path is not suppoted

查看:89
本文介绍了应用程序路径不受支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在vb.net中使用应用程序路径?
但是应用程序路径在vb.net中不起作用.

how to used app path in vb.net?
but app path is not working in vb.net.
what to do?

推荐答案

最好的方法可能是这样:
The best method is probably this:
string exeFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
string exeDirectory = System.IO.Path.GetDirectoryName(exeFilePath);



如果找到应用程序的入口程序集的主要可执行模型的位置(您的入口点通常是方法Main),无论调用此代码的程序集是什么.

请注意,有许多解决此问题的方法,但是其中许多都不是很好.例如,Application.StartupPath要求System.Windows.Forms,其他方法取决于应用程序的托管方式(例如,对于Windows Service应用程序或在调试器下可能无法正常工作),但是我已演示的方法始终可以正常工作. br/>

—SA



If founds the location of the main executable model of the entry assembly of the application (where you entry point is, usually the method Main), regardless of the assembly where this code is called.

Note, there are many solutions of this problems, but many of them are not so good. For example, Application.StartupPath requires System.Windows.Forms, other methods depend on how application is hosted (for example, may not work correctly for a Windows Service application or under debugger), but the method I''ve demonstrated always work correctly.

—SA


尝试一下
您将不得不使用
Try this
You will have to use
System.AppDomain.CurrentDomain.BaseDirectory()


代替


instead of

App.Path


如果您的要求是从应用程序启动位置获取文件夹,那么我认为Application.StartupPath属性可能有用如此处所述
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx#Y0 [
If your requirement is to obtain the folder from where the application has started then I think Application.StartupPath property may be useful as explained here
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.startuppath.aspx#Y0[^]


这篇关于应用程序路径不受支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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