我有一个包含两张工作表的excel文件,其中包含超过150列。当我尝试使用文件上传控件将这个文件上传到服务器时,我得到了一个错误,说“请求不正确”。这是我正在编写的代码。
protected void BtnSubmit_Click(object sender, EventArgs e)
{
string path;
if (FUExcel.HasFile)
{
try
{
path = Server.MapPath(".") + "\\UploadedFiles\\" + Guid.NewGuid() + FUExcel.FileName;
FUExcel.PostedFile.SaveAs(path);
Server.ScriptTimeout = 4000;
LblMsg.Text = "Upload status: File uploaded!";
ExcelLOBServices.ExcelSheetNames(path);
ExcelLOBServices.columnNamessheet1(path);
ExcelLOBServices.columnNamessheet2(path);
}
catch (Exception ex)
{
LblMsg.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
} 发布于 2012-01-11 13:38:30
在ASP.NET中,默认的最大文件上载大小仅为4MB左右。您需要更新您的web.config以允许更大的大小。如果你想允许20MB,你可以这样做:
<system.web>
<httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>点击此处阅读更多信息:
http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx
发布于 2012-01-11 13:40:43
在你的web.config中,你需要更新最大请求长度。默认设置为4096 (4 Mb)。
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>https://stackoverflow.com/questions/8814639
复制相似问题