SSRS: Relative URL Hyperlink

2020-03-20 10:31发布

In SSRS 2008 I would like to create a relative path URL. Long story short I have a subscription that outputs a few thousand static HTML pages to a folder that is used as content for a website. In the past I have created full URLs to other pages on the site (sub-reports, really) using Text Box Properties -> Action -> Go to URL. I would like to modify my code so that it returns the relative path of the target instead of the full URL. This will reduce the likelyhood that someone will eventually break the navigation by changing the website domain or folder structures. When I tried to make this work, the objects that were previously clickable are no longer, well, clickable. How do I make a SSRS hyperlink jump to a relative URL instead of a fully-qualified URL?

Here's what works:

="https://some.domain.com/some_page/" + Fields!Custom_Page_Name.Value.ToString() + ".html"

Here's what doesn't work:

="../" + Fields!Custom_Page_Name.Value.ToString() + ".html"
="/" + Fields!Custom_Page_Name.Value.ToString() + ".html"
=Fields!Custom_Page_Name.Value.ToString() + ".html"
="..\" + Fields!Custom_Page_Name.Value.ToString() + ".html"
="\" + Fields!Custom_Page_Name.Value.ToString() + ".html"

5条回答
成全新的幸福
2楼-- · 2020-03-20 10:45

Just use global variable Globals!ReportServerUrl

So "http://myservername/rs?/myreportname" becomes Globals!ReportServerUrl + "?/myreportname"

查看更多
太酷不给撩
3楼-- · 2020-03-20 10:51

If you look at the warning generated when you run the report in Visual Studio you'll get your answer:

[rsInvalidURLProtocol] The value ‘test.html’ of the Hyperlink property of the text box ‘textbox6’ has an invalid schema. URLs in reports may only use http://, https://, ftp://, mailto: or news:

i.e. URLs must have one of those protocols, and since there's no way of writing a relative URL when it starts with the protocol that means SSRS doesn't support relative URLs.

An alternative would be to set the base URL in a parameter, which would then be easily changed and would only require regenerating your html pages if it changes.

查看更多
Explosion°爆炸
4楼-- · 2020-03-20 10:56

Just read this Q and A and have a better solution for anyone looking. If you want relative url then just use javascript e.g.

="javascript:void(window.navigate( '/mydirectory/reportcountry.aspx?CountryID=" + Fields!CountryID.Value.ToString() + "'))"
查看更多
来,给爷笑一个
5楼-- · 2020-03-20 10:57
="javascript:void(window.open(document.URL.replace('CurrentReportName','NavigateToReportName'),'Window1','menubar=no,width=430,height=350,toolbar=no'));"

I know it's a old post. it may help someone..Note: I am using SSRS 2008

查看更多
看我几分像从前
6楼-- · 2020-03-20 10:59

In Visual Studio 2013 with SQL Server Data Tools you can access the property pages for a label. This gives the option to link to another report (in the same project) and pass any parameters as required:

Screenshot of property pages.

查看更多
登录 后发表回答