JPJ*_*edi 18 vb.net executable desktop-application visual-studio-2008
我需要获取运行我的应用程序的路径(不是可执行文件):
System.AppDomain.CurrentDomain.BaseDirectory()
Run Code Online (Sandbox Code Playgroud)
当我在我的本地机器上使用&"/images/image.jpg"运行上述语句时,它运行正常,但是当我在另一台机器上安装该应用程序时,它说它无法找到该文件,并且有一些额外的路径信息.
我只需要运行应用程序的目录.我使用Visual Studio 2008在VB.NET中编码.
谢谢!
Der*_*mba 27
这是google上的第一篇文章,所以我想我会发布不同的可用方式以及它们的比较方式.不幸的是我无法弄清楚如何在这里创建一个表,所以它是一个图像.每个代码都使用完全限定名称在图像下方.
My.Application.Info.DirectoryPath
Environment.CurrentDirectory
System.Windows.Forms.Application.StartupPath
AppDomain.CurrentDomain.BaseDirectory
System.Reflection.Assembly.GetExecutingAssembly.Location
System.Reflection.Assembly.GetExecutingAssembly.CodeBase
New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase)
Path.GetDirectoryName(Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path)))
Uri.UnescapeDataString((New System.UriBuilder(System.Reflection.Assembly.GetExecutingAssembly.CodeBase).Path))
Run Code Online (Sandbox Code Playgroud)
Jus*_*ner 25
Dim strPath As String = System.IO.Path.GetDirectoryName( _
System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
Run Code Online (Sandbox Code Playgroud)
MrC*_*vin 13
Dim P As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
P = New Uri(P).LocalPath
Run Code Online (Sandbox Code Playgroud)
小智 11
在记住环境课之前,我需要知道这一点并来到这里.
如果其他人有这个问题,请使用:Environment.CurrentDirectory.
例:
Dim dataDirectory As String = String.Format("{0}\Data\", Environment.CurrentDirectory)
Run Code Online (Sandbox Code Playgroud)
在调试模式下从Visual Studio运行时:
C:\Development\solution folder\application folder\bin\debug
Run Code Online (Sandbox Code Playgroud)
这是我需要的确切行为,简单而直接.