In below code I am canceling file upload when user tries to upload a file other than an image file.
But when I cancel the file it shows below error.
protected string[] ValidExtensions = new string[] { "png", "jpeg", "gif", "jpg" };
public override void ItemAdding(SPItemEventProperties properties)
{
base.ItemAdding(properties);
string strFileExtension = Path.GetExtension(properties.AfterUrl);
bool isValidExtension = false;
string strValidFileTypes = string.Empty;
foreach (string strValidExt in ValidExtensions)
{
if (strFileExtension.ToLower().EndsWith(strValidExt.ToLower()))
{
isValidExtension = true;
}
strValidFileTypes += (string.IsNullOrEmpty(strValidFileTypes) ? "" : ", ") + strValidExt;
}
//// Here i am going to check is this validate or not if not than redirect to the
////Error Message Page.
//problem in canceling file upload
if (!isValidExtension)
{
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "Only Images are Allowed !";
}
}
Error
Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed.
Details: To enable the details of this specific error message to be viewable on the local server machine, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "RemoteOnly". To enable the details to be viewable on remote machines, please set "mode" to "Off".
<!-- Web.Config Configuration File -->
<configuration>
<system.web>
<customErrors mode="RemoteOnly"/>
</system.web>
</configuration>
I tried to change the web.config file it still gives above error