StackTrace
StackTrace

Reputation: 9416

Exception Details: System.Web.HttpException: Maximum request length exceeded

Am trying to read data from an Excel file into an ADO.NET Dataset using the code below. In a windows Forms application it work, 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 of reading an Excel file from a client machine into an ADO.NET DataTable in ASP.NET

Upvotes: 5

Views: 14840

Answers (1)

K D
K D

Reputation: 5989

Add following tag in your web.config file and check if it works

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

Upvotes: 26

Related Questions