SharePoint Permission problem when programming Object model with trust level WSS_Minimal

Hi,

 

Last few days I was playing with SharePoint server 2007 and programming with it. All I was trying to do was add a list item in a simple list created in the SharePoint through a web part. The code to do the job was simple enough.

SPWeb site = SPContext.Current.Web;
SPList list = site.Lists["Vikram Site List"];
SPListItem newItem = list.Items.Add();
newItem ["Title"] = "http://www.VikramLakhotia.com";
newItem.Update();

But when I deployed the code it started giving me Permission error. It was very difficult to know from the error itself on what was the actual problem. The actual error was

 

Request for the permission of type 'Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, ' Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' failed.

 

I could not follow what problem can be there with permission in the line of code that I wrote. Later on googling the error code I found that the error was caused if you are running the SharePoint application with security policy WSS_Minimal. To be able to program against SharePoint Object model we need to change the security policy to WSS_Medium. This can be done by changing the trust level in the web.config file.

<trust level="WSS_Minimal" originUrl="" />

to

<trust level="WSS_Medium" originUrl="" />

This will solve the problem. Also note the medium trust level policy allows you to program against SharePoint object model and access NT event log.

Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Posted on 3/16/2008 9:40:21 PM

Vikram
I have faced same problem when ever I try to populate the webparts with any SPSite object.I think There is a problem with installing onto web application with Minimal trust level.For now you can work around by setting trust to Medium or Full.

Posted on 4/22/2008 1:35:07 AM

I am trying to use ASP.NET AJAX in sharepoint,I have use all the procedures i.e installing asp.net,editing the web.comfig and master file,but when ever I applied textbox auto-complete in sharepoint it did'nt work but it works on my local computer.Your help would be really appreciated.

Posted on 7/15/2008 2:01:43 AM

Hello,

I thisnk you can solve your problem by setting the following before updating the item

site.AllowUnsafeUpdates = true

try it !

Regards

André

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2008 Vikram Lakhotia