2009-01-02 45 views
6

我试图用一个hyperlinkbutton在Silverlight使用户下载word文档。我不关心保存为文件的文件是否出现,或者文档是否在新浏览器中打开。我收到错误“无法导航到相对于页面的位置”。我已经看到了它贴,你可以做到这一点的绝对路径(www.domain.com/filename.doc),但一定是一种方法,使这种相对(/docs/filename.doc)。任何人都知道吗?的Silverlight ... hyperlinkbutton到文件中使用相对路径

回答

4

的HyperlinkBut​​ton只与绝对URL工作,所以你应该在运行时修正内容网址:从Silverlight.net forums

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

+0

好了...这似乎是它主要是解决我的问题...有没有一种方法,使与卡西尼工作? – GWTF 2009-01-04 06:25:05

+0

没关系它与卡西尼工作太...我只是在路径 – GWTF 2009-01-04 07:29:43

13

稍微容易:

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