Uploading a file type that is not supported (.exe, .chm, ) is causing the site to throw an application error. How to block these file types and provide a error that the file type is not supported.
Should this be done through itemadding event handler or is there any other way to handle it.
Use regular expression validator for this, refer below article
w: http://www.worldofsharepoint.com | t: @sharesandip
I tried this:
string beforeUrl = properties.BeforeUrl;
string extension = beforeUrl.Substring(beforeUrl.LastIndexOf('.') + 1);
if ((extension.ToLower().Equals("exe")) || (extension.ToLower().Equals("chm")))
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Please upload a valid document.";
properties.Cancel = true;
I am still getting the application error page. Am i missing something here.
I have set debug to false, and callstack set to true. I need to set callstack to true for some other purpose, so i will not able to change to false.
- Edited by Venkatzeus Tuesday, September 13, 2011 12:24 PM
Thanks for your post.
Please try to unblock the file type in Central Administration at first, and then you can use the ItemAdding Event Handler to block the file types and show custom error message.
Thank you very much for the reply.
Even i thought the same. However, if the file extensions increase.. then the list would go for a toss.
It is better blocking it from central Admin and it would be great if there was a way to show customized messages.