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 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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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;
                }
            }
        }
share|improve this answer
    
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. –  Rahil Jan Muhammad Apr 26 '13 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; } } } –  Anand May 15 '13 at 8:26

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.