代码之家  ›  专栏  ›  技术社区  ›  Scott Anderson

银色灯光。..使用相对路径指向文件的超链接按钮

  •  6
  • Scott Anderson  · 技术社区  · 17 年前

    我试图使用silverlight中的超链接按钮,使用户能够下载word文档。我不在乎是否出现文件另存为框,也不在乎word文档是否在新浏览器中打开。我收到错误“无法导航到相对于页面的位置”。我看到它发布了,你可以用绝对路径(www.domain.com/filename.doc)来做到这一点,但必须有一种方法使其相对(/docs/filename.doc。有人知道怎么做吗?

    2 回复  |  直到 17 年前
        1
  •  13
  •   Anon99    16 年前

    稍微容易一点:

    Uri myAbsoluteUri = new Uri(HtmlPage.Document.DocumentUri, myRelativePath);
    
        2
  •  4
  •   Michael S. Scherotter    17 年前

    HyperlinkButton仅适用于绝对URL,因此您应该在运行时修复您的URL:

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

    来自 Silverlight.net forums .