Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I code the relative path for the URI?

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
Hello,

I know this is so simple I just must be tired.

I have written a c# class for my business layer.

When I create an XMLReader with the physical path of the XML file it works fine. But for production I do not know exactly what the path will be be.

How do I pass in the relative path to the application rather than the physical path?

Thanks in advance.

Code:
XmlReader xRdr = XmlReader.Create("c:/Projects/myappfolder/myappsubfolder/myxmlfile.xml", xRdrSet);
 
you can just use .Create("myappsubfolder\myxmlfile.xml") but this will cause the file to be created in the current working directory (not necessarily your app)

So use

using System.IO;

.Create(Path.GetDirectoryName(Application.ExecutablePath) + "\\myappsubfolder\myxmlfile.xml")
 
Thanks for info but the file isn't being created. It's being accessed in order for the xmlreader to be created (the XMLReader will be reading the file).

Also, I can't use Application.ExecutablePath because it resides under System.Windows.Forms which is not availble to me as I'm working with a class...not a windows application.

Any other ideas?
 
System.IO.Path.GetDirectoryName(System.Environment.ExecutablePath);


Try that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top