Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

xmlTextReader path to file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rob Taylor - 09 Oct 2007 17:30 GMT
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
Vadym Stetsiak - 10 Oct 2007 13:26 GMT
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 ***
Rob Taylor - 10 Oct 2007 19:56 GMT
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
Vadym Stetsiak - 11 Oct 2007 10:52 GMT
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 ***
Rob Taylor - 11 Oct 2007 16:48 GMT
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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.