validationeventssharepointsharepointdocumentlibrary

Display a success message to user in a SharePoint Document Library after validation in ItemAdding Event


When validating a document in the ItemAdding event there are many ways to display errors to the user, but there doesn't seem to be a way to display successes to user, like a validation was successful. An info message to the user at the top of document library would be great.

public class MyItemEventReceiver : SPItemEventReceiver {
    public MyItemEventReceiver() {}
    public override void ItemAdding(SPItemEventProperties properties) {
            // Do some validation
            // If successful display message to user - can't seem to do
            // If unsuccessful cancel and go to the error page - easy
        }
    }
}

Solution

  • In the event handler you have a Property called Cancel when set to true it will redirect you to the Error Page. Whereas when you dont distrub it, it will redirect you to the Metadata page of the document, i.e it will as you for the Name and Title of the document. Being said that out of the Box it is not possible to archive what you want to do. One alternate approach I would suggest is that once the validation is successful, set a Flag in the Session / Property Bag of the List with the Document GUID as the Key and in the Final Landing page deploy a Custom Web Part that will check for the this GUID and if there is a Value then It will display the Message.