So, on my ItemAdded receiver, I am looking to update a list item field. Now, if the user adding the item to the list, has sufficient permissions/privileges, this all runs smoothly. If not, the code will error on the properties.ListItem.Update();
line. Not ideal.
Where my understanding falls down, is that I am running this update within a SPSecurity.RunWithElevatedPrivleges
block. Code below;
public override void ItemAdded(SPItemEventProperties properties)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
properties.ListItem["Title"] = "Some Text"
properties.ListItem.Update();
});
}
catch (Exception ex)
{ }
}
The error I'm currently getting is an "unauthorised access" error. The process seems to running under the credentials of the user rather than the System account (as I would expect of I were running with elevated privileges?)
Any suggestions would be much appreciated
SPDiagnosticsService.Local.WriteTrace
for write in the SharePoint logs the error raised in the try/ catch block. After that, run again the code and check in the log files.