2010-06-08 107 views
2

我在.net的winform项目中有一个名为reports的目录。我的项目名称是AccountingReports,并且存在Directory目录报告。所以我需要通过代码访问此路径的方式。在Asp.net中,我们使用Request.PhysicalApplicationPath属性。那么,有没有任何方法或属性存在,这将使我的根我的项目如何获取我的WinForm应用程序项目中的目录路径

回答

8

的你可以使用:

Directory.GetCurrentDirectory

获取应用程序的当前工作目录。

然后,您可以使用附加的 “报告” 到以下几点:

Path.Combine(string, string)

Dim reportsFolder As String 
reportsFolder = Path.Combine(Directory.GetCurrentDirectory(), "Reports") 
+0

仍然给我\ bin \ debug [可执行文件的当前工作目录],所以我需要把报告放到调试目录中来测试我的应用程序...&进一步安装的位置将是AppInstallDir/Reports /它的工作...我是对的吗? 没有其他办法铭记.. – 2010-06-08 11:06:21

+0

@Amit - 是的,除非你把位置放到app.config目录并从那里读取。 – ChrisF 2010-06-08 11:52:00

+0

然后在这种情况下,在部署之后,用户每次移动Reports目录时都需要更新app.config文件。 – 2010-06-08 12:13:37

1

当IDE与安装我用运行:

如果System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed - 如果已安装,则为true false IDE

已安装 - System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

IDE - My.Application.Info.DirectoryPath

+0

仍然相同My.Application.Info.DirectoryPath = \ bin \ debug – 2010-06-08 12:17:20

+0

无论如何,我需要做一些解析字符串或复制粘贴到可执行目录..通常感谢您的支持.. – 2010-06-08 12:19:20

+0

它总是有趣得到downvotes在一个六年的职位,没有任何解释... – dbasnett 2016-03-14 23:18:49

5
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\") 
+0

这是唯一一个在开发VSTO加载项时为我工作的人。因为没有抓住这个,所有人都感到羞耻。 – Lopsided 2016-03-14 05:35:39

0

嘛。可能迟了一点,但我只是有同样的问题,并像这样解决:

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) 

有了这个路径包含在'PathLb'。

希望它对任何人都有用。

相关问题