Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

silverlight...hyperlinkbutton to file using relative path

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?

like image 679
Scott Anderson Avatar asked Jan 02 '09 01:01

Scott Anderson


2 Answers

Slightly easier:

Uri myAbsoluteUri = new Uri(HtmlPage.Document.DocumentUri, myRelativePath);
like image 60
Anon99 Avatar answered Nov 09 '22 14:11

Anon99


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.

like image 38
Michael S. Scherotter Avatar answered Nov 09 '22 16:11

Michael S. Scherotter