Question

What Event in Event Receiver should I use to catch the item uploading event? Seems that ItemAdding or ItemAdded can not catch the event

Était-ce utile?

La solution

First of all, which environment are you using, 2007, 2010 or 2013?

Here's a generic explanation: ItemAdding fires before the item is added, which means you can get the object before it is added to the list. You can use HttpContext to do this. This gives you the opportunity to show an error message and abort if something doesn't look right.

When the ItemAdded event is fired, the object is already in the list and you can manipulate it if you want to. Hope this helps.

Autres conseils

uploading with the following code, the file being uploaded won't be added into library. so same can be used to catch the event.

class ShareDocEventHandler : SPItemEventReceiver
{
HttpContext htcntxt = null;
public ShareDocEventHandler()
{
  htcntxt = HttpContext.Current;
}

public override void ItemAdding(SPItemEventProperties properties)
{

  base.ItemAdding(properties);
  properties.Cancel = true;

}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top