silverlight…hyperlinkbutton to file using relative path

╄→尐↘猪︶ㄣ 提交于 2020-01-24 03:28:12

问题


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?


回答1:


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.




回答2:


Slightly easier:

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


来源:https://stackoverflow.com/questions/405812/silverlight-hyperlinkbutton-to-file-using-relative-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!