Frage

I am using NavigationWindow to display html files, it worked fine until path does not contain any # or illegal characters.

I just wanted to know is there a way to open html file when the path contains URL fragment, for example: an anchor # like below..

"c:\MyFile.Html#tips"

Currently i am getting the following exception...

Could not find file 'c:\MyFile.Html#tips'
System.Net.WebException was unhandled 

  HResult=-2146233079
War es hilfreich?

Lösung

The problem is with the creation of the URI, it seems there is some bug with the URI class.

The URI generated by the following are different,

var filePath = @"c:\MyFile.Html#tips";   
var uri = new Uri(filePath);
var uri2 = new Uri("file://" + filePath);

Fragment part of the uri is empty, but uri2 has correct fragment part as "#tips".

The same kind of problem is with the query even after creating URI as uri2, the reported bug for query string can be found here, Why doesn't System.Uri recognize query parameter for local file path? and Uri class does not parse filesystem URL with query string

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top