silverlight ...使用相对路径的文件超级链接按钮 [英] silverlight...hyperlinkbutton to file using relative path
问题描述
我正在尝试在Silverlight中使用超链接按钮使用户能够下载Word文档。我不在乎是否会出现另存为文件框,或者是否在新的浏览器中打开doc一词。我收到错误消息无法导航到相对于页面的位置。我已经看到它发布了您可以使用绝对路径(www.domain.com/filename.doc)进行此操作,但是必须有一种使之相对的方法(/docs/filename.doc)。有人知道吗?
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?
推荐答案
HyperlinkButton仅适用于绝对URL,因此您应在运行时修复URL:
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);
这篇关于silverlight ...使用相对路径的文件超级链接按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!