2

I have a standard document library. I want to prompt the user if file name already exists in document library. I want this Friendly Error (with custom error text) on "Upload Document" form when when user clicks 'OK' button. I don't want to show default SharePoint Error page.

1 Answer 1

1

You can write a List Item Receiver (Synchronous).

More specific "Item Adding" event receiver, where you can get the current file name & check it against the existing items & show a message.

UPDATE:

public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            if (CheckIfExisting()) //this is where you call yout private method to check file names
            {
                try
                {
            properties.Cancel = true;
                    properties.ErrorMessage = "Please choose some other name.";
                }
                catch (InvalidCreatorIdException ex)
                {
                    properties.Cancel = true;
                    properties.ErrorMessage = ex.ToString();
                    properties.InvalidateListItem();
                    throw;
                }
            }
        }
2
  • I can identify duplicate in event receiver but I need to show message in UI. Is it possible that Event throws an message to UI.
    – Raheel
    Apr 26, 2013 at 0:45
  • Use below code: public override void ItemAdding(SPItemEventProperties properties) { base.ItemAdding(properties); if (CheckIfExisting()) //this is custom method { try { properties.Cancel = true; properties.ErrorMessage = "Please choose some other name."; } catch (InvalidCreatorIdException ex) { properties.Cancel = true; properties.ErrorMessage = ex.ToString(); properties.InvalidateListItem(); throw; } } } May 15, 2013 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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