SSRS Reporting Services Web Part
I've built a report but I need to get a paramater from the sharepoint url that is hosting the report. So, is there a way to parse the host url so that I can get this value. For example: http://devServ/Jobs/21000 is the site url for the sharepoint site that will run the report. The 21000 in the URL and is a number I need to grab to use as a parameter. I need to grab this from the sharepoint url because this report will be hosted on thousands of sites. Each site will have a different number (ie http://devServ/Jobs/21001 or http://devServ/Jobs/21002) that represents a different job number. So, I want to create a site template that I can deploy over and over again without having to go in and modify the actual report to contain a new number every time a new site is created. Hopefully I was able to explain this well enough. Is this even possible? Thanks Craig
April 26th, 2011 12:26pm

Hi Craig, From your description, I noticed you need to get the SharePoint site URL in report as a parameter. However, generally we can only use the global field ReportServerUrl to get the URL of the Report Server. So, I am trying to involve someone familiar with this topic to further look at this issue. This might be some time delay. Appreciate your patience and understanding. Regards, Tony ChainTony Chain [MSFT] MSDN Community Support | Feedback to us Get or Request Code Sample from Microsoft Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2011 5:28am

I gave it a shot but didn't get all the way there. thought I'd share my efforts and results anyway. function doit() return System.Web.HttpContext.Current.Request.url end function I added this function tot he codebehind and referenced it from a text box using the expression =Code.doit() I also had to reference system.web to get access to that library. I got #error. I don't know if that's because that library is not allowed given the security restrictions on the codebehind or what.. you can google that and find some info. Just an idea that you might be able to pursue.. I don't even know if the codebehind is able to modify a parameter or if that's too late in the stack.
April 27th, 2011 10:10am

Hi, In order to accomplish this task, create a custom assembly. Below is an example which can be modified as you want. Note that this particular example will not work in the Visual Studio designer since you are trying to access a url from the current web page and the Report Designer preview mode is not a web page. So, for your benefit and others who would like to test their custom assembly in Visual Studio preview mode, I will include necessary changes that need to be made to the Visual Studio Report Designer. 1. First you have to create a class project. In my case I created a C# project. Then, you have to add a reference to the System.Web assembly and add the namespace. using System; using System.Web; namespace GetCurrentPageUrl { public class GetPageUrl { string pageurl = string.Empty; public string GetUrl() { //Use can take this further and use string manipulation to get exactly what you want pageurl = HttpContext.Current.Request.Url.AbsoluteUri; return pageurl; } } } 2. Build the solution and copy the custom assembly to the Report Server bin folder as well as the Report Designer (for Visual Studio). Please note, on 64 bit machines, the Report Designer folder will be in the Program Files (x86) folder. Also, if the Report Server is 32 bit on a 64 bit machine, you will have to add the custom dll to the Program Files (x86) folder. Report Server bin folder: <drive name>\Program Files\Microsoft SQL Server\MSRS10.<instance_name>\Reporting Services\ReportServer\bin Visual Studio Report Designer folder: <drive name>\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies 3. The next step is to modify the "RSPreviewPolicy.config" (for Visual Studio Report Designer) as well as the "rssrvpolicy.config" "rssrvpolicy.config" <drive name>\Program Files\Microsoft SQL Server\MSRS10.<instance_name>\Reporting Services\ReportServer "RSPreviewPolicy.config" <drive name>\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies a) Locate the last <CodeGroup .... and add your codegroup below it. Do this for both the Report Server and the Visual Studio Report Designer. <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="FullTrust" Name="<Give_it_a_Name>" Description="<Your description>"> <IMembershipCondition class="UrlMembershipCondition" version="1" Url="<Url_to_your_custom_dll.dll>" /> </CodeGroup> b) The Report Server service has to be restarted for the changes to take effect. 4. Now go to your Report Designer and click on the Report menu and click on "Report Properties". a) Once in the Report Properties window, click on "References". b) Under the Add or Remove Assemblies, click on Add. Then browse to your custom assembly. c) Then, under the Add or Remove Classes, click on Add. Here you will have to add the namespace.classname. Example: GetCurrentPageUrl.GetPageUrl d) For the Instance name, you can put any name you want. This is the name you will use to access the method in the report. Example: MyInstance e) Click on OK to accept changes. 5. To test the custom assembly in your report, you can use an expression that looks like the following: =Code.MyInstance.GetUrl() 6. Since this particular assembly needs access to a web page, it will not work in the Report Designer. You will have to deploy the report to your SharePoint site. Browse to the report and you should see your url/parameter as required. Reference =========== Using Custom Assemblies with Reports - http://msdn.microsoft.com/en-us/library/ms153561(v=SQL.100).aspx Thanks, Cathy Miller Microsoft Online Community Support
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2011 4:21pm

Thanks so much for everyones effort. I didn't think anyone replied because I wasn't getting email responses that someone had replied. I'll give this a shot and see what happens and I'll report back.
May 4th, 2011 5:54pm

Thank you. That worked awesome
Free Windows Admin Tool Kit Click here and download it now
May 6th, 2011 11:08am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics