Tuesday, February 9, 2010

Access denied error while Editing List Items in SharePoint(MOSS 2007)

Sometimes, we get access denied error while editing (Edit properties) the list item even though we have access to the Sharepoint list.
Also, View History link on the Sharepoint list item throws access denied issue

This is a issue with Sharepoint and we need to execute the code to the SP libraries to fix the problem. The source code for this app is as follows. Put this in a console app and pass the site URL and list name as parameters.
This is working code and solved our production issue.

string RenderXMLPattenAttribute = "RenderXMLUsingPattern";
string weburl = "http://localhost/sites/Test/";
string listName = "Test Library";
SPSite site = new SPSite(weburl);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[listName];
SPField f = list.Fields.GetFieldByInternalName("PermMask");
string s = f.SchemaXml;
Console.WriteLine("schemaXml before: " + s);
XmlDocument xd = new XmlDocument();
XmlElement xe = xd.DocumentElement;
if (xe.Attributes[RenderXMLPattenAttribute] == null)
XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);
attr.Value = "TRUE";
string strXml = xe.OuterXml;
Console.WriteLine("schemaXml after: " + strXml);
f.SchemaXml = strXml;
Console.WriteLine("Process completed");


Anonymous said...

where exactly we have to put this code...???

Anonymous said...

Where do you put this code?

Saravana said...

Just run this code against the SharePoint list that gives the error.