Click here to Skip to main content
15,891,993 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 22 MB excel file .. i need to upload it from asp.net page.
I have used the below code.. But it is not working when file size is larger

C#
uploadfile = fileuploadExcel.PostedFile.FileName;
            filename = Path.GetFileName(uploadfile);
            extension = Path.GetExtension(uploadfile);
            String fname, spath;
            spath = Server.MapPath(@"ExcelFile/" + filename);
            fname = filename;
            if (System.IO.File.Exists(fname))
            {
                System.IO.File.Delete(fname);
                fileuploadExcel.SaveAs(spath);
            }
            else
            {
                fileuploadExcel.SaveAs(spath);
            }
            path = fileuploadExcel.PostedFile.FileName;
            excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + path + ";" + "Extended Properties=Excel 8.0;";
            excelConnection = new OleDbConnection(excelConnectionString);
            OleDbCommand cmd = new OleDbCommand("Select * from [Sheet4$]", excelConnection);
            excelConnection.Open();
            OleDbDataReader dReader;
            dReader = cmd.ExecuteReader();
            SqlBulkCopy sqlBulk = new SqlBulkCopy(connectionstring);
            sqlBulk.DestinationTableName="Rawdata";
            sqlBulk.WriteToServer(dReader);
            excelConnection.Close();
            excelConnection.Dispose();


please suggest me/share the code
Posted
Updated 13-Oct-11 9:29am
v2

1 solution

You can increase the limit by modify the Web.Config file. The attribute "maxRequestLength" describes this feature.

maxRequestLength:Attribute indicates the maximum file upload size supported by ASP.NET.The size specified is in kilobytes. The default is "4096" (4 MB).

Example:
XML
<system.web>
  <httpRuntime executionTimeout="240" maxRequestLength="20480" />
</system.web>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900