Using relative path in WPF/Xaml

Creating a new Uri for a relative file path (like "myfolder\myfile.txt") in WPF will result in an UriFormatException being thrown. This is because the parser has no idea what type of path it is. Uri's is far more than "c:\myfile.txt" and you can read all about it over at Microsoft. But to keep it simple, this is what a relative Uri should be written like:

Uri myRelativeUri = new Uri("pack://siteoforigin:,,,/myfolder/myfile.txt");

Related posts:

Comments

comments powered by Disqus