I would expect something like this to work but the ListItem, BeforeProperties, AfterProperties are all null/empty. I need the file name and file content.
public class MyItemEventReceiver : SPItemEventReceiver {
public MyItemEventReceiver() {}
public override void ItemAdding(SPItemEventProperties properties) {
SPListItem item = properties.ListItem;
bool fail = item.File.Name.Equals("fail.txt");
if (fail) {
properties.ErrorMessage = "The file failed validation";
properties.Cancel = true;
}
}
}
I can't use ItemAdded as it is asynchronous and I need to be synchronous, I may prevent the upload and display a message to the user.
Any suggestions would be appreciated. For example, is it possible to override the Upload.aspx?