Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i kept my xml file in the following path
i need to get this path dynamically
where sample xml is my project file name
D:\OfficeWork\practice\SampleXml\SampleXml


i am getting executable file by using this path D:\OfficeWork\practice\SampleXml\SampleXml\bin\Debug
Posted

C#
Dim path As String = Application.StartupPath
Dim found As Boolean = False
Do
    found = File.Exists(System.IO.Path.Combine(path, "sample.xml"))
    If Not found And path.Length > 3 Then
        path = System.IO.Path.GetDirectory(path)
    End If
Loop While Not found OrElse String.IsNullOrEmpty(path)

If found Then
    path = System.IO.Path.Combine(path, "sample.xml")
    ' do something with the path
End If
 
Share this answer
 
I would suggest for simplicity that you add the SampleXml file to your project and then select it in your solution explorer. In the properties window select the "Copy to output directory" and make sure it is set to Copy always or Copy if newer. Then it will appear in the bin\Debug directory when you build and you can just reference the file name instead of having to calculate an absolute path for the file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900