PATH in Debug mode

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
in my win application I've a file named myFile.xml at the root of my
application: in debug mode, when I try to read this file, the runtime
application searches it in the path bin/debug... and it doesn't find it
because there isn't there, so I've used the function:

Path.GetFullPath("../../myFile.xml")

thanks to this function it works, but when I try to deploy the application,
it doesn't work anymore, because path is different... How can I set a
flexible path at the deployment and in my code?

Please help me.
 
Hi Siu,

Well, you could store the path to the file in the registry, a local config file or in UserAppDataPath etc.
 
Hello,

From the project property pages -> Common properties -> Build events you can
set a Post-build Event Command line to something like this:

copy "$(SolutionDir)myFile.xml" "$(TargetDir)myFile.xml"

This means that you can always assume that the file will be in the root
directory of your application.

Hope this helps,

David
 
Siu said:
in my win application I've a file named myFile.xml at the root of my
application: in debug mode, when I try to read this file, the runtime
application searches it in the path bin/debug... and it doesn't find it
because there isn't there, so I've used the function:

Path.GetFullPath("../../myFile.xml")

thanks to this function it works, but when I try to deploy the
application,
it doesn't work anymore, because path is different... How can I set a
flexible path at the deployment and in my code?

In Windows Forms applications you can use 'Application.StartupPath', in
console applications/class libraries you can use the code below:

\\\
Imports System.IO
Imports System.Reflection
..
..
..
Private Function ApplicationPath() As String
Return _
Path.GetDirectoryName([Assembly].GetEntryAssembly().Location)
End Function
///
 
Back
Top