Evyatar Evyatar - 1 year ago 134
C# Question

Remove file:// prefix c#

I have the follow:

string file = string.Concat(

Now file is:


How can i remove the "file:\" prefix?


Answer Source

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; 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download