I am looking for a simple way to check the extension of the uploaded file, if it was PDF file do something, else a warning message will show that its (wrong file type), but the problem with my code is if I selected any file type instead of PDF it will show the error page with this message:
Server Error in '/' Application.
PDF header signature not found.
Exception Details: iTextSharp.text.exceptions.InvalidPdfException: PDF header signature not found.
<asp:FileUpload runat="server" ID="file1" AllowMultiple="true" />
string fileName = Path.GetFileName(file1.FileName);
FileInfo fi = new FileInfo(fileName);
string ext = fi.Extension;
if (ext == ".pdf")
{
//do something
}
else
Label1.Text = string.Format("wrong file type");