I am currently developing an Event Handler for SharePoint 2010 which sets defaults for Document Libraries on creation (content types, version settings etc). I am having a problem with Save Conflicts when creating Document Libraries through the GUI, the event receiver doesn't always run after the GUI is done saving the list.
I assumed ListAdded would be called after the GUI has properly finished creating the list and saved it, but it doesn't seem to be the case. I have tried setting properties in the ListAdding function, but changes are not saved (as the list isn't created yet).
I receive the following message when debugging in Visual Studio:
Save Conflict.
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
with the stack trace of:
Microsoft.SharePoint.SPException was unhandled by user code
ErrorCode=-2130575305
NativeErrorMessage=FAILED hr detected (hr = 0x81020037)
NativeStackTrace=""
Message=Save Conflict.
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
Source=Microsoft.SharePoint
StackTrace:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.SetListProps(String bstrUrl, String bstrListName, Boolean bMigrate)
at Microsoft.SharePoint.SPList.Update(Boolean bFromMigration)
at Company.SharePoint.EventReceivers.ListCreate.CompanyListCreateEventReceiver.ListAdded(SPListEventProperties properties)
at Microsoft.SharePoint.SPEventManager.RunListEventReceiver(SPListEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPListEventProperties properties, String receiverData)
at Microsoft.SharePoint.SPEventManager.RunListEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.<>c__DisplayClassc`1.<InvokeEventReceivers>b__6()
at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)
InnerException: System.Runtime.InteropServices.COMException
and the ULS logs of:
02/25/2011 11:12:52.06 w3wp.exe (0x363C) 0x219C SharePoint Foundation General 8e2s Medium Unknown SPRequest error occurred. More information: 0x8007047e f35857af-3d3a-462c-86a6-de24d3b3d8d3
02/25/2011 11:12:52.06 w3wp.exe (0x363C) 0x219C SharePoint Foundation General 72k4 Medium <nativehr>0x8007047e</nativehr><nativestack></nativestack> f35857af-3d3a-462c-86a6-de24d3b3d8d3
02/25/2011 11:12:52.06 w3wp.exe (0x363C) 0x219C SharePoint Foundation General 8kh7 High <nativehr>0x8007047e</nativehr><nativestack></nativestack> f35857af-3d3a-462c-86a6-de24d3b3d8d3
Is there a way of ensuring the conflict doesn't happen, or a different way of setting or accessing the list properties which won't conflict. I have tired creating a seperate instance of SPSite/SPWeb, but that still has the same issue.
A simple example of the code which is failing is:
public class CompanyListCreateEventReceiver : SPListEventReceiver
{
public override void ListAdded(SPListEventProperties properties)
{
base.ListAdded(properties);
SPList l_list = properties.List;
l_list.Title = "Changed title";
l_list.Update();
}
}
Any help would be appreciated. Thanks!
