I have a file upload page with an AsyncFileUpload control. When the user browses to the file the upload control pulls the file into memory. I then have an Upload button which fires the following code to save the file to a database.
I am finding that if files are over about 500KB then the FileBytes property of the control simply returns null. This happens on my server but when running the app locally it runs through fine.
I'm not handling the OnUploadCompleted event as I need to user to complete further information before committing the file to database.
I have this in my web.config: httpRuntime maxRequestLength="10000"/>
private void UploadDocument(int mietID)
{
if (Page.IsValid)
{
if (mietID > 0)
{
if (File1.HasFile && File1.FileBytes != null)
{
string[] docFormats = MIETPConfig.Current.SupportedDocumentFormats;
for (short i = 0; i < docFormats.Length; i++)
docFormats[i] = docFormats[i].ToUpper();
if (docFormats.Contains(Path.GetExtension(File1.FileName).ToUpper()))
{
try
{
byte[] uploadedBytes = File1.FileBytes;
DocumentController.CreateDocument(txtLinkText.Text, Path.GetFileName(File1.PostedFile.FileName), uploadedBytes, mietID, (User)Session["User"]);
MietpClientScripts.CloseWindow(Page);
}
catch (Exception)
{
lblUploadStatus.Text = "There was an error saving the document to the database.";
}
}
else
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (string s in docFormats)
sb.Append(s + ", ");
sb.Remove(sb.Length - 2, 2);
lblUploadStatus.Text = "Invalid file format, only these formats are supported: " + sb.ToString();
}
}
else
{
lblUploadStatus.Text = "There was an error saving the document, the document could not be read; it might be too large to upload.";
}
}
else
lblUploadStatus.Text = "No Mietp ID to associate document with.";
}
}