SharePoint programming and permission problem
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