xmlTextReader path to file

R

Rob Taylor

I've inherited a .NET project that I'm debugging the code to. I'm
completely new to .net as well. I have a line in my code that reads an
XML file, however, I cannot figure out the reference point that a
relative path starts from. I.e., the following line

XmlTextReader reader = new XmlTextReader( "..\\..\\..\\filename.xml" )

points to "BaseURI "file:///C:/Program Files/filename.xml" string

When I step through the code even though my project is in
c:\projects\... I don't want to hard code a path into the code as that
wouldn't be practical. What is it starting point for the relative path
and how can I change it?

Thank you.

Rob
 
V

Vadym Stetsiak

Hello, Rob!

Environment.CurrentDirectory contains path of the current working directory.
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Tue, 09 Oct 2007 09:30:55 -0700:

RT> I've inherited a .NET project that I'm debugging the code to. I'm
RT> completely new to .net as well. I have a line in my code that reads
RT> an
RT> XML file, however, I cannot figure out the reference point that a
RT> relative path starts from. I.e., the following line

RT> XmlTextReader reader = new XmlTextReader( "..\\..\\..\\filename.xml"
RT> )

RT> points to "BaseURI "file:///C:/Program Files/filename.xml" string

RT> When I step through the code even though my project is in
RT> c:\projects\... I don't want to hard code a path into the code as
RT> that wouldn't be practical. What is it starting point for the
RT> relative path and how can I change it?

RT> Thank you.

RT> Rob


RT>
 
R

Rob Taylor

Vadym,

Thank you. That definitely helps! However, I cannot figure out how
this property is being set in the different projects I've tested as I've
search for the existence of this code and cannot find any reference to
it. Can this be set in a configuration dialog box somewhere?

Thank you.

Rob
 
V

Vadym Stetsiak

Hello, Rob!

If I recall correctly, working directory (current dir) is set by the process
that launches the application.
If you want to change it, you can do in the the app inintialization code.
For instance, in the main routine.

At first you take the path where executing or entry assembly is located (
Assembly.GetExecutionAssembly().Location ).
Then take directory info from that path ( Path.GetDirectoryName(...) ) and
then set current directory (Environment.CurrentDirectory)

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Wed, 10 Oct 2007 11:56:51 -0700:

RT> Vadym,

RT> Thank you. That definitely helps! However, I cannot figure out how
RT> this property is being set in the different projects I've tested as
RT> I've search for the existence of this code and cannot find any
RT> reference to it. Can this be set in a configuration dialog box
RT> somewhere?

RT> Thank you.

RT> Rob

RT>
 
R

Rob Taylor

Vadym,

That explains a lot about why I get different CurrentDirectory values
depending upon what project I test with. Your solution sounds very
doable. Thank you. I'll try that out and get back with the results.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top