Solved

Relative URL in ReportViewer Action

Posted on 2014-09-08
14
455 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

18 Experts available now in Live!

Get 1:1 Help Now