SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an ItemUpdated event receiver in a document library in SharePoint 2010.

When I try to upload a document with a name that already exists in my library I get an error message "The specified name is already in use". That is fine.

But the ItemUpdated event is fired anyway and I don't want my code to run if no document was added. Does anyone know how to work around this?

share|improve this question
up vote 0 down vote accepted

Yup, it is possible, however you will have to make changes to your event receiver,

public override void ItemAdding(SPItemEventProperties properties)
  if (CheckIfDocumentAlreadyExists(properties.Item.File.Name))
    properties.Cancel = true;
    properties.ErrorMessage = "Some error has occured....";

and then create a method named as CheckIFDocumentAlreadyExits and put code where it will check if file exists or not,

share|improve this answer

My method:

private bool CheckIfDocumentAlreadyExists(SPItemEventProperties properties)
    bool documentExists = false;
    if (!string.IsNullOrEmpty(properties.AfterUrl))
        var existingDocument = properties.Web.GetFile(properties.AfterUrl);
        documentExists = existingDocument.Exists;
    return documentExists;
share|improve this answer

Your Answer


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.