开发者

How do I get path of the Directory inside my WinForm app project

开发者 https://www.devze.com 2023-01-03 04:32 出处:网络
I have a d开发者_运维百科irectory 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

I have a d开发者_运维百科irectory 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


You can use:

Directory.GetCurrentDirectory

Gets the current working directory of the application.

You can then append "Reports" to that using the following:

Path.Combine(string, string):

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


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\")


When running in the IDE vs. Installed I have used:

If System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed - true if installed, false IDE

installed - System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory

IDE - My.Application.Info.DirectoryPath


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'.

Hope its useful to anyone.

0

精彩评论

暂无评论...
验证码 换一张
取 消