ItemAdding event – is the list item a file or a folder?




In event receivers other than ItemAdding it is a simple task to determine if the current item is a file or a folder. You would write something along the lines of:

bool isFile = (properties.ListItem.File != null);

However in the ItemAdding event properties.ListItem is null. This is because the list item is yet to be created. In order to determine if the current item is a file, you should instead try this:

bool isFile = (properties.AfterProperties["vti_filesize"] != null);

You are welcome!




Leave a Reply

Your email address will not be published.