views:

2196

answers:

2

I am trying to use a hyperlinkbutton in silverlight to enable the user to download a word document. I don't care if a file save as box appears or if the word doc opens in a new browser. I get the error "cannot navigate to locations relative to a page." I've seen it posted that you can do this with the absolute path (www.domain.com/filename.doc) but there's got to be a way to make this relative (/docs/filename.doc). Anyone know how?

+4  A: 

The HyperlinkButton only works with absolute URLS, so you should fixup your URLs at runtime:

uriCurrent = System.Windows.Browser.HtmlPage.Document.DocumentUri;
string current = uriCurrent.OriginalString;
int iLastSlash = current.LastIndexOf('/') + 1;
current = current.Remove(iLastSlash, current.Length - iLastSlash);

from Silverlight.net forums.

Michael S. Scherotter
Okay...that seems like it mostly solves my problem...is there a way to make that work with Cassini?
Scott Anderson
Nevermind it works with Cassini too...I just had to append "ClientBin" in the path
Scott Anderson
A: 

Slightly easier:

Uri myAbsoluteUri = new Uri(HtmlPage.Document.DocumentUri, myRelativePath);
Anon99