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
The default maximum filesize is 4MB - this is done to prevent denial of service attacks in which an attacker submitted one or more huge files which overwhelmed server resources. If a user uploads a file larger than 4MB, they'll get an error message: "Maximum request length exceeded." Server Error in '/' Application.
Locate the following line: <httpRuntime maxRequestLength="100000" executionTimeout="1800" /> . Change the maxRequestLength to a value (in KB) equal to the maximum object size configured in vFire. The maximum value supported for web. config is 2147483647.
Add following tag in your web.config file and check if it works
<httpRuntime maxRequestLength="350000" enableVersionHeader="false" maxQueryStringLength="3584" executionTimeout="600"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With