I have an ItemAdded event handler connected to a document library, in order to automatically populate certain fields when a new document is uploaded:
public class AutoPopulateDocumentFields : SPItemEventReceiver
{
public override void ItemAdded(SPItemEventProperties properties)
{
base.ItemAdded(properties);
SPList sourceList = properties.List;
sourceList["Title"] = "Auto-populated title value";
try {
this.EventFiringEnabled = false;
sourceList.Update();
}
finally {
this.EventFiringEnabled = true;
}
}
}
This usually works when uploading a new file. I get an intermittent error, though: Sometimes the update list item form which shows up after upload does not have the "Title" field autofilled, and when clicking "OK" I get the error message
The file "Documents\testfile.txt" was changed by Geir Smestad on the 18. Nov 2011 11:28:47 +0100
This is a SharePoint error, not an error in my code. After closing the error, the Title has the value "Auto-populated title value" but all other fields have their default values. What is wrong?