in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

This Blog

Syndication

All About SharePoint - S.S. Ahmed - MVP Microsoft SharePoint

All About SharePoint, as the name suggests, is all about SharePoint. It has articles, tutorials, source code, FAQs, and tips about SharePoint, InfoPath, C#, Microsoft Office, SQL Server, XML, etc.

How to grant permissions to a custom assembly that is referenced in a report in Reporting Services

It seems straight forward. Isn't it? but it may not be as simple and straight forward for the newbies as it seems at first. A colleague and a  friend of mine recently was struggling with the same issue and he learnt the lesson after spending considerable amount of time experimenting with different solutions. You get a security exception when you write your own component to be used in a report in reporting services. My friend is working on a SharePoint project that involves reporting services. He created a report that used a custom built component. The code used SharePoint object model. He tried to use Elevated privileges but even that didn't work because the error is thrown on the line that has the elevated priviliges code. He even tried the code access security, that didn't work. The following KB article has information about this problem:

 http://support.microsoft.com/kb/842419/ (How to grant permissions to a custom assembly that is referenced in a report in Reporting Services)

Use following code to get rid of the security exception:

SharePointPermission perm = new SharePointPermission(PermissionState.Unrestricted);
perm.Assert();

//Code using SharePoint object model here!!

perm.Deny();

Include following DLL in the references before you use the above code:

Microsoft.SharePoint.Security.DLL

This DLL will be found in the 12 hive. Exact location is as following:

System Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\

Add following namespaces at the top:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using System.Security.Permissions;

That's it. Your component will now work fine.

Comments

 

SharePoint MVP Blogs said:

It seems straight forward. Isn't it? but it may not be as simple and straight forward for the newbies

June 19, 2008 2:59 PM
 

mike said:

Wow!  This post saved me.  I was having problems deploying a custom webservice to sharepoint, and this fixed the problem.

Thanks for all of your great work and information sharing.

Please, please keep up it up!

July 30, 2008 5:26 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

About ssa

MOSS MVP - Over 8 years experience. 4 years SharePoint experience!

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts