Sunday, 8 September 2013

Path.Combine (System Path) Uri Bad Encoding?

Path.Combine (System Path) Uri Bad Encoding?

I use
var path = new
Uri((System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
To get my exe file location (I want to use CodeBase not Location because
it's not reliable I need original file location on disk)
The issues with this it's Uri... when I continue on and use for example
string CreatedFolder = "MyApp";
var pathdir = Path.GetDirectoryName(path);
string pathfinal = Path.Combine(pathdir, CreatedFolder);
The results looks like it's working looks like everything is ok.
C:\Users\user\Desktop\Sources For Projects\Project\Project1\bin\Debug\MyApp
When trying to access to this folder from file explorer (I just enter the
path in the path bar to get quickly to that folder)
I get an error "Windows cannot find 'C:\Users\user\Desktop\Sources' make
sure you've typed the name correctly.
As you can see it doesn't detect anything after the space... encoding
problem because Uri. How can I fix this?

No comments:

Post a Comment