New Information on WebClient in Silverlight 2

September 28, 2008
No Comments.

Silverlight Logo
After digging and some prodding by a PM at Microsoft, I realize that the relative URI story in WebClient is different that I expected.  I am not sure whether this changed from previous versions but Beta 2 and the RC this is the way that Relative URI’s work in WebClient:

  • WebClient supports a BaseAddress property (read/write) that by default contains the path to the .xap file (though you could replace it with HtmlPage.Document.DocumentUri.ToString() to resolve to the current page).
  • It uses the BaseAddress to calculate the relative URI.
  • This is not the same as the Image/Media “Site of Origin” relative URI problem (see my post about that here).
  • In most cases a relative URI in WebClient will do the right thing and supporting the BaseAddress will allow you to change the basis for the relative URI’s pretty easily.

Note that the WebRequest classes (BrowserHttpRequest specifically) does not support relative URI’s so if you want to use that class instead of WebClient, you’ll have to do your own relative URI resolution.