samedi 18 avril 2015

File Upload Validation asp

I try to validate FileUpload control to check the extension of files by this regular expression



<asp:RegularExpressionValidator ID="RegularExpressionValidator5" ValidationGroup="PersonalGroup"
ControlToValidate="FileUpload1" Runat="Server"
ErrorMessage="Only .pdf & .doc files are allowed" ValidationExpression="[^\.]\.pdf\.docx\.doc$" />*</asp:RegularExpressionValidator>


my problem to check the FileUpload already has file or not before i click the button submit because i got NullReferenceException if don't have file i try to make this



if (FileUpload1.HasFile)
{
book.Book_File = System.IO.Path.GetPathRoot(FileUpload1.PostedFile.FileName);
}


but the problem still exist if the user didn't uploaded any file. How to check the FileUpload is required filed before submit?


Aucun commentaire:

Enregistrer un commentaire