代码之家  ›  专栏  ›  技术社区  ›  user240141

如何获取WinForm应用程序项目中目录的路径

  •  2
  • user240141  · 技术社区  · 14 年前

    我在.NET中的winform项目中有一个名为reports的目录。我的项目名是accountingreports,目录报告中存在。所以我需要通过代码访问这个路径的方法。在ASP.NET中,我们使用Request.PhysicalApplicationPath属性。因此,是否存在任何方法或属性可以为我提供项目的根目录?

    4 回复  |  直到 8 年前
        1
  •  8
  •   LBPLC    8 年前

    你可以使用:

    Directory.GetCurrentDirectory

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

    然后,您可以使用以下方法将“报告”附加到该报告:

    Path.Combine(string, string) :

    Dim reportsFolder As String
    reportsFolder = Path.Combine(Directory.GetCurrentDirectory(), "Reports")
    
        2
  •  6
  •   eldarerathis sreeji    12 年前
    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\")
    
        3
  •  0
  •   rahulserver    11 年前

    在IDE和已安装的IDE中运行时,我使用了:

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

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

    IDE My.Application.Info.DirectoryPath

        4
  •  0
  •   Zatiel    10 年前

    好。可能晚了一点,但我也遇到了同样的问题,我就这样解决了:

        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”中。

    希望它对任何人都有用。