Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom list which I have written a SPItemEventReciever for and it works. But when I do the same for a document library it doesn't fire. Is there anything I have to do if it is a document library?

Sample code below.

public class OrderHandler : SPItemEventReceiver { public override void ItemAdded(SPItemEventProperties properties) { GenerateID(properties); }

public override void ItemUpdated(SPItemEventProperties properties) { GenerateID(properties); }

void GenerateID(SPItemEventProperties properties) { SPListItem order = properties.ListItem;

string customer = order["Customer"].ToString(); string orderDate = Convert.ToDateTime(order["OrderDate"]).ToShortDateString();

order["OrderID"] = customer + " " + orderDate; order.Update();

} }

Do I need to treat a list different if it's a document library?

share|improve this question
add comment

1 Answer

Have a look through this list of Event Receiver Troubleshooting hints:

http://msdn.microsoft.com/en-us/library/aa979520.aspx

I think you might want to disable event firing before updating a list item, though.

share|improve this answer
    
Thanks.If i want to rename the filename when uploading a document.Should i be looking at ItemsAdded or ItemUpdating?? –  Patrick Nov 15 '10 at 13:05
    
ItemAdded, change the AfterProperties and disable event firing so ItemUpdating isnt called immediately after,too. –  James Love Nov 15 '10 at 14:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.