I've been using the FileUpload control to upload a large file. Everything works fine on localhost, but on the server, the file gets corrupt: the upload goes well, the file has correct size, but the contents are mixed up, some parts of the file are written over others.
E.g. like this:
Original file:
abcdef0123456789
Uploaded file:
abc1230123456789
There is about one segment like this per 10 MBs of the file, the length varies, typically 0.1-1 kB.
My code is simple:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="UploadTest.Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
</div>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit" />
</p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
And the server side:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace UploadTest
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(AppDomain.CurrentDomain.BaseDirectory + "\\Files\\" + FileUpload1.FileName);
Label1.Text = "Success " + FileUpload1.FileName;
}
else {
Label1.Text = "No file";
}
}
}
}
It does not matter what file I try to upload, the large ones (> 10 MB) get corrupted.
I think that this has no business with the code, but it is related to something else (but it does not happen on my client computer only and I need solution simple enough to explain it to the other person using it, if this is client-related). I've tried to disable the antivirus software and it had no effect. But also, there are some clients that handle the data upload correctly.
What else can mess up my post data?
Any ideas? Thanks, AlesP
Post edited