Wednesday, October 27, 2010

How to solve Microsoft.SharePoint.SPException: A file with the name xxx already exists. It was last modified by SHAREPOINT\system on xxx

In the workflow, if the workflow needs to update the column/field of the current workflow list item, i.e., workflowproperites.listitem, workflowproperties.listitem.update() will cause above exception. To solve this problem, the workflow needs to retrieve the listitem independently, as suggested by this blog by


My resolution is to add a simple property to my WF class. What it will do is ensure that I always load up the SPListItem every time I need it.

private SPListItem WorkflowItem
{
    get
    {
        SPDocumentLibrary library = (SPDocumentLibrary)WorkflowProperties.Web.Lists[WorkflowProperties.ListId];

        return library.GetItemById(WorkflowProperties.ItemId);
    }
}


There are many suggestions about how to fix this problem, but this one did it for me.