Solved

Relative URL in ReportViewer Action

Posted on 2014-09-08
14
483 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now