Solved

Relative URL in ReportViewer Action

Posted on 2014-09-08
14
498 Views
Last Modified: 2014-09-11
Using a report viewer in an ASP web application and need to have one of the columns as a hyperlink to another page on the same site using a relative URL, but it is only working if I put in an absolute URL

For example:

This works ==> http://localhost:12345/myPage.aspx
This doesn't ==> ~/myPage.aspx

Obviously when I deploy the website the server name will change, so it can't be hard coded.

Is it possible to use relative url's?
0
Comment
Question by:BrianFord
  • 7
  • 6
14 Comments
 
LVL 12

Expert Comment

by:Ramkisan Jagtap
ID: 40311429
I think relative path is not supported in the ReportViewer, So please write some custom code and create and  add URL from there.
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 40311434
As far as I know relative paths for the Go To URL action are not supported, the first part (http) is crucial for SSRS to figure out what protocol to use for the navigation.

To avoid the issue of having to update each action when the server changes you can store the first part of the URL in a hidden report parameter and use an expression to build the URL for the action.  Then you only need to update that parameter on deployment.
Another option, if you really want to avoid the hardcoded server name, is to store it in a config table in a database and set up a small dataset to retrieve it.
0
 

Author Comment

by:BrianFord
ID: 40311803
Thanks,

I'm not really an expert on report expressions, do you know if it's possible to query the current server name as part of the expression? so that entering something like:

="HTTP://" & <current servername> & "/myPage.aspx"
or
=<current URL> & "/myPage.aspx"

would mean not having to change the data on deployment
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 37

Expert Comment

by:ValentinoV
ID: 40311816
There is a global variable that returns the URL of the report server: Globals!ReportServerUrl

The string returned goes like this: http://yourserver/reportserver

Perhaps you can extract info out of that to be used in the URL expression?  However, this variable will only return useful info if your report server is running on the same box as your web server, if you need to refer to a website URL at least (as your example indicates).
0
 

Author Comment

by:BrianFord
ID: 40311889
My report is a 'local Report' and therefore not on a report server.

I do have a class in my project that contains a function to return the current URL which I am trying to use but I can't figure out how to reference this class/function in an expression:

For example, I have a class called myFunctions.vb with a method called getUrl
I have tried adding a reference to it but I get the error: myFunctions.vb is not defined
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 40311923
Ow okay, in that case I think the ReportServerURL doesn't return anything at all...

Would it be an option to add a hidden parameter to the report and pass the result of your getUrl function into it?  As far as I'm aware (I usually don't use local reports) technically this should be possible.
0
 

Author Comment

by:BrianFord
ID: 40311931
yes that would be an option, but that's what I can't figure out how to do :)
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 40311952
The VB code would go something like this:

Dim param As New ReportParameter("TheReportParamName", getUrl())
ReportViewer1.LocalReport.SetParameters(New ReportParameter() {param})

Open in new window

Ref LocalReport.SetParameters Method
0
 

Author Comment

by:BrianFord
ID: 40313250
Thanks guys, I finally got this to work so the hyperlink actually loads the required page now.

I'm currently using this expression:
=Parameters!pURL.Value & "/main.aspx?contactID=" & Fields!contactID.Value

Open in new window


which yields the text: http://localhost:49856/main.aspx?contactID=21 and the action works great.

However, I would much rather it just displayed the word 'Select' in the link instead of a long URL, just like a normal html hyperlink
0
 

Author Comment

by:BrianFord
ID: 40314128
any ideas how to do this
0
 
LVL 37

Accepted Solution

by:
ValentinoV earned 500 total points
ID: 40314198
"However, I would much rather it just displayed the word 'Select' in the link instead of a long URL, just like a normal html hyperlink"

I'm not sure what you mean with that.  The action itself doesn't display anything, the text that gets displayed on the report is what is located in the textbox on which the action is defined.  Perhaps you put the URL expression as content for the textbox?  There's no need for that, it can contain anything you like.
0
 

Author Comment

by:BrianFord
ID: 40315504
Sorry, I'm confused and I'm sure I haven't set this up properly but...

The text in the textbox is the expression (=Parameters!pURL.Value & "/main.aspx?contactID=" & Fields!contactID.Value) that creates the url address that I want to Jump To

So design time looks like this:
Design Time
And when the report runs it looks like:
Run time
0
 

Author Closing Comment

by:BrianFord
ID: 40315773
Got it working based on your responses.

Thank you very much for your help
0
 
LVL 37

Expert Comment

by:ValentinoV
ID: 40316358
Nice to hear, good luck with the project!

VV
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question