I have the follow:
string file = string.Concat(
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase
),
"bla.xml");
Now file is:
file:\C:\test\Debugbla.xml
How can i remove the "file:\" prefix?
Thanks
Uri class is the way to manipulate Uri. While string.Replace
is an option it is better to use tools explicitly designed for particular case which also take care of handling escaping rules where necessary.
string file = string.Concat(System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), "bla.xml");
file = new Uri(file).AbsolutePath;
UPDATE:
More robust implementation eliminating string.Concat
to handle other cases including fragments in the codebase url.
var codebase = new Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
var file = new Uri(codebase, "bla.xml").AbsolutePath;
Use the Assembly.Location
property instead, which returns a normal filepath.
Also, use Path.Join()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With