Reputation: 574
I am using following code to save product images. When I upload 5 images, It runs fine but when I upload 6 images, it gives me exception of Maximum Request Length Exceed
protected void Button1_Click(object sender,EventArgs e)
{
string filepath = Server.MapPath("UploadFiles");
HttpFileCollection uploadedFiles = Request.Files;
Span1.Text = string.Empty;
for(int i = 0;i < uploadedFiles.Count;i++)
{
HttpPostedFile userPostedFile = uploadedFiles[i];
try
{
if (userPostedFile.ContentLength > 0)
{
Span1.Text += "File Content Type: " + userPostedFile.ContentType + "<br>";
Span1.Text += "File Size: " + userPostedFile.ContentLength + "kb<br>";
Span1.Text += "File Name: " + userPostedFile.FileName + "<br>";
userPostedFile.SaveAs(filepath + "\\" + Path.GetFileName(userPostedFile.FileName));
Span1.Text += "Location where saved: " + filepath + "\\" + Path.GetFileName(userPostedFile.FileName) + "<p>";
}
}
catch(Exception Ex)
{
Span1.Text += "Error: <br>" + Ex.Message;
}
}
}
I did not make any changes in web.config also. can any body guid me where can i change the maximum request length exceed limit. I googled it but did not find the answer. Thanx
Upvotes: 2
Views: 1830
Reputation: 148110
You need to set in web.config
using httpRuntime tag
<configuration>
<system.web>
<httpRuntime maxRequestLength="1048576" />
</system.web>
</configuration>
Optional Int32 attribute. Specifies the limit for the input stream buffering threshold, in KB. This limit can be used to prevent denial of service attacks that are caused, for example, by users posting large files to the server. The default is 4096 (4 MB), reference.
Upvotes: 4