I'm using a FileUpload control to allow users to upload a file to an SQL database.
I have a button which I use to load the selected file via C# code.
However if the file size is of certain size the upload fail. I have a break point on the C# code which never gets hit when the size is to large but it does when the file size is OK. This is where I would have put the check but the break point doesn't get hit!??!
What's the best way to implement this? Should I use JavaScript?
The C# code behind the button is below but it never get fired:
protected void buttonAddDocumentType_Click(object sender, EventArgs e)
{
int size = fileUploadDocument.PostedFile.ContentLength;
//This is where I'd like to perform the file size check
byte[] fileData = new byte[size];
fileUploadDocument.PostedFile.InputStream.Read(fileData, 0, size);
WebDataAccess.InsertDocument(Int32.Parse(Request.QueryString["ID"].ToString()), Int32.Parse(comboDocumentTypes.SelectedValue), fileUploadDocument.FileName, fileUploadDocument.PostedFile.ContentType,
fileUploadDocument.FileBytes.Count(), fileData);
comboDocumentTypes.SelectedIndex = -1;
}
I'm using ASP.Net 4.0
Thanks in advance.