views:

59

answers:

2
string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
string exeDir = Path.GetDirectoryName(exeFile);
string fileName = Path.Combine(exeDir, @"..\..\xml\SalesOrderXMLData.csv.xml");

Hello,
The above code works if the project is in, for example,

C:\Code\

but not if its in

C:\Documents and Settings\Naim\My Documents..

If i have the string, i would use escape characters where needed, but in this case, i dont know how to get around this.

Update: result fileName = "D:\Naim\My%20Documents\Visual%20Studio%202008\Projects\XML_Gen\XML_Gen\bin\Debug\..\..\xml\SalesOrderXMLData.csv.xml" Any help appreciated.
Thanks

A: 

It's probably the URI. Use Assembly.GetEntryAssembly().Location, and pass it directly to Path.GetDirectoryName().

nitzmahone
A: 

code below works, though I don't know why the above wasn't working. Changed AbsolutePath to LocalPath

string exeFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).LocalPath;
string exeDir = Path.GetDirectoryName(exeFile);
string fileName = Path.Combine(exeDir, @"..\..\xml\SalesOrderXMLData.csv.xml");
Slabo