vb.net 如何在我的 WinForm 应用程序项目中获取目录的路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2996246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get path of the Directory inside my WinForm app project
提问by Casey
I have a directory named reports inside my winform project in .net. My project name is AccountingReports and inside that Directory reports exists. So i need the way to access this path via code. In Asp.net we use Request.PhysicalApplicationPath property. So is there any method or property exists that will give me the root of my project
我在 .net 中的 winform 项目中有一个名为 reports 的目录。我的项目名称是 AccountingReports,并且在该目录中存在报告。所以我需要通过代码访问这条路径的方法。在 Asp.net 中,我们使用 Request.PhysicalApplicationPath 属性。那么是否存在任何方法或属性可以为我提供项目的根
回答by ChrisF
You can use:
您可以使用:
Gets the current working directory of the application.
获取应用程序的当前工作目录。
You can then append "Reports" to that using the following:
然后,您可以使用以下内容附加“报告”:
Dim reportsFolder As String
reportsFolder = Path.Combine(Directory.GetCurrentDirectory(), "Reports")
回答by Casey
Dim path As String = AppDomain.CurrentDomain.BaseDirectory
'replace \bin\Debug\ the part of the path you dont want with part you do want
Dim path1 As String = path.Replace("\bin\Debug\", "\htmlFiles\")
回答by Zatiel
Well. A lil' bit late maybe, but I just had the same problem and solved it like this:
好。也许有点晚了,但我只是遇到了同样的问题并像这样解决了它:
Dim Path As String() = Directory.GetCurrentDirectory.ToString.Split(New Char() {"\"c})
For i = 0 To Path.Count - 3
PathLb.Text = PathLb.Text & "\" & Path(i)
Next i
PathLb.Text = PathLb.Text.Remove(0, 1)
With this the path is contained on 'PathLb'.
这样,路径就包含在“PathLb”中。
Hope its useful to anyone.
希望它对任何人有用。
回答by dbasnett
When running in the IDE vs. Installed I have used:
在 IDE 与已安装中运行时,我使用了:
If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
- true if installed, false IDE
如果System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
- 如果安装为真,则为假 IDE
installed - System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory
安装 - System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory
IDE - My.Application.Info.DirectoryPath
IDE - My.Application.Info.DirectoryPath