Exception Details: System.Web.HttpException: Maximum Request Length Exceeded

I am trying to read data from an Excel file in an ADO.NET dataset using the code below. In a Windows Forms application this works, but in an asp.net application it fails.

 public static DataTable ArchiveData(string fileName)
{
    FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read);

    //Reading from a OpenXml Excel file (2007 format; *.xlsx)
    IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
    excelReader.IsFirstRowAsColumnNames = true;

    DataSet result = excelReader.AsDataSet();

    //Free resources (IExcelDataReader is IDisposable)
    excelReader.Close();
    return result.Tables["Archive data"];
}

Stack trace:

[HttpException (0x80004005): Maximum request length exceeded.]
   System.Web.HttpRequest.GetEntireRawContent() +8793522
   System.Web.HttpRequest.GetMultipartContent() +62
   System.Web.HttpRequest.FillInFormCollection() +236
   System.Web.HttpRequest.get_Form() +68
   System.Web.HttpRequest.get_HasForm() +8745879
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
   System.Web.UI.Page.DeterminePostBackMode() +63
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133

OR is there a better way to read an Excel file from a client machine in ADO.NET DataTable in ASP.NET

+5
source share
1 answer

Add the following tag to your web.config file and see if it works

<httpRuntime maxRequestLength="350000" enableVersionHeader="false" maxQueryStringLength="3584" executionTimeout="600"/>
+26
source

All Articles