I have an SPListEventReceiver that handles the ListAdded event. If checks that the list is a Document Library, and then adds some fields to the library:
public class ListEventReceiver : SPListEventReceiver
{
public override void ListAdded(SPListEventProperties properties)
{
if (properties.List.BaseTemplate == SPListTemplateType.DocumentLibrary)
{
// Add fields here
}
base.ListAdded(properties);
}
}
When a list is created using SharePoint's web UI, the event works perfectly. However, when the list is created by the code below, the event is not fired, and the fields are not added:
SPWeb spWeb = ...;
SPListTemplate listTemplate = ...; //Find relevant DocLib template
Guid newListId = spWeb.Lists.Add(title, description, listTemplate);
EDIT: I do not have the option of changing the EventReceiver - it was created by a third party, and I have no control over it.
base.ListAdded(properties);before your custom code. Can you debug and verify that your event is fired and condition is met? – Vedran Rasol Feb 7 '12 at 21:12SPListTemplateType(not onlyDocumentLibrarywhich has code 101, but other codes). – Kai Feb 8 '12 at 7:25