Path.Combine with spaces in the passed parameter?

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 located, for example,

C: \ Code \

but not if its in

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

If I have a string, I will use escape characters where necessary, but in this case I do not know how to get around this.

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

+3
source share
2 answers

The code below works, although I do not know why the above does not work. 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");
0

, , URI. Assembly.GetEntryAssembly(). Path.GetDirectoryName().

0

Source: https://habr.com/ru/post/1721467/


All Articles