Why does IsWellFormedOriginalString fail on file Uris?
.net, c#, uri
Solution
Your URI is not well-formed.
A well-formed example would be `file:///C:/Temp/test.html`.
PS Home:> (new-object Uri 'file:///C:/Temp/test.html').IsWellFormedOriginalString()
True
PS Home:> (new-object Uri 'file:///C:\Temp\test.html').IsWellFormedOriginalString()
False
PS Home:> (new-object Uri 'C:\Temp\test.html').IsWellFormedOriginalString()
False
PS Home:> (new-object Uri 'C:/Temp/test.html').IsWellFormedOriginalString()
False
Problem
I have code like this: ``` string uriString = @"C:\Temp\test.html"; Uri uri = new Uri(uriString); bool goodCond = uri.IsWellFormedOriginalString(); ``` But goodCond is false! What am I doing wrong? Edit: Thanks Johannes and Catdirt. I'll focus my question: How do I convert a valid file path to a valid file Uri (using uri.IsWellFormedOriginalString as an indication to the validity of the Uri)? Take a look at this: ``` DirectoryInfo di = new DirectoryInfo(@"c:\temp"); FileInfo [] fis = di.GetFiles("test.html"); FileInfo fi = fis[0]; string uriString = fi.FullName; Uri uri = new Uri(uriString); bool goodCond = uri.IsWellFormedOriginalString() ``` Obviosly fi.fullName is a well formed path, but still goodCond is bad!