views:

318

answers:

2

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
        }
    }
}
+3  A: 

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.

Kusek
A: 

Umm... edit List's AllItems.aspx or edit your masterpage, add Literal control to it. At ItemAdded event just refer to that control and set it's value.

Maybe it turns out you even need code-behind for that masterpage. Refer here.

Janis Veinbergs
ItemAdded event is Async Event there is Not Guarantee that it will get fired immediately.Also there no Guarantee that the Page is going to get redirected to the AllItems.aspx page. I would say Itemadded Event will be a bad Idea.
Kusek
Well, if you edit masterpage, then you do not need to be redirected to AllItems.aspx to have that control. But the other point makes sense.
Janis Veinbergs