Pages

Mar 1, 2012

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

Solution
This is a issue with Sharepoint and we need to execute the code to the SP libraries or lists 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://Pravyns/sites/Test/";
string listName = "Test Library";
SPSite site = new SPSite(weburl);
SPWeb web = site.OpenWeb();
Console.WriteLine(web.Name);
SPList list = web.Lists[listName];
SPField f = list.Fields.GetFieldByInternalName("PermMask");
string s = f.SchemaXml;
Console.WriteLine("schemaXml before: " + s);
XmlDocument xd = new XmlDocument();
xd.LoadXml(s);
XmlElement xe = xd.DocumentElement;
if (xe.Attributes[RenderXMLPattenAttribute] == null)
{
XmlAttribute attr = xd.CreateAttribute(RenderXMLPattenAttribute);
attr.Value = "TRUE";
xe.Attributes.Append(attr);
}
string strXml = xe.OuterXml;
Console.WriteLine("schemaXml after: " + strXml);
f.SchemaXml = strXml;
Console.WriteLine("Process completed");
Console.ReadLine();

No comments: