HighTechTalks DotNet Forums  

xmlTextReader path to file

Dotnet Framework microsoft.public.dotnet.framework


Discuss xmlTextReader path to file in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Rob Taylor
 
Posts: n/a

Default xmlTextReader path to file - 10-09-2007 , 12:30 PM






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


*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #2  
Old   
Vadym Stetsiak
 
Posts: n/a

Default Re: xmlTextReader path to file - 10-10-2007 , 08:26 AM






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> *** Sent via Developersdex http://www.developersdex.com ***



Reply With Quote
  #3  
Old   
Rob Taylor
 
Posts: n/a

Default Re: xmlTextReader path to file - 10-10-2007 , 02:56 PM





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

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #4  
Old   
Vadym Stetsiak
 
Posts: n/a

Default Re: xmlTextReader path to file - 10-11-2007 , 05:52 AM



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> *** Sent via Developersdex http://www.developersdex.com ***




Reply With Quote
  #5  
Old   
Rob Taylor
 
Posts: n/a

Default Re: xmlTextReader path to file - 10-11-2007 , 11:48 AM



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

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.