Is it possible to show user friendly error message for files blocked in central administration.
I have a site, which has a document library. when the user tries to upload files which are blocked in the central administration, I want to show a user friendly message.
I checked this:http://technet.microsoft.com/en-us/library/cc262496.aspx
for blocked file types.
I tried to check the Item Adding event, but before the item adding event is called for the site, I am getting the server application error.
I tried this in Item Adding event:
base.ItemAdding(properties);
string CentralAdminUrl = SPAdministrationWebApplication.Local.AlternateUrls[0].IncomingUrl;
string beforeUrl = properties.BeforeUrl;
string extension = beforeUrl.Substring(beforeUrl.LastIndexOf('.') + 1);
Uri myUri = new Uri(CentralAdminUrl);
SPWebApplication myWebApp = SPWebApplication.Lookup(myUri);
if(myWebApp.BlockedFileExtensions.Contains(extension))
{
properties.ErrorMessage = "Please upload a valid document.";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
But this code is not executed, before this I am getting the server application error.
How to fix this? Any help on this.