Click here to Skip to main content
15,907,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,

I'm not able to upload larger file using the below codings..i tried with 20mb file and its uploaded without any problem. but when i tried to upload 80mb file , the upload fails.. it doesn't returns any error though.. even i'm getting "successfully uploaded" message but nothing was uploaded actually.. But when i run the application locally , that is , on asp.net server , i'm able to upload even 90mb file.. so the problem starts only after hosting the site.. am i have to add ant server side coding for this?.. i have no idea about this.. pls help me...

HttpFileCollection uploadFilCol = Request.Files;
                try
                {
                    for (int i = 0; i < uploadFilCol.Count; i++) //uploadFilCol.Count
                    {
                        HttpPostedFile file = uploadFilCol[i];
                        string fileExt = Path.GetExtension(file.FileName).ToLower();
                        string fileName = Path.GetFileName(file.FileName);
                      
                        if (file.ContentLength > 0)
                        {

                            if (fileName != string.Empty)
                            {
                               
                                createdir(ftpaddress + Session["userid"].ToString(), user, pass);
                                try
                                {
                                   
                                    if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".png" || fileExt == ".jpeg" || fileExt == ".rar" || fileExt == ".zip" || fileExt == ".7z")
                                    {
                                       
                                        FtpWebRequest uploadRequest = (FtpWebRequest)FtpWebRequest.Create(ftpaddress + Session["userid"].ToString() + @"/" + fileName);
                                        Stream requestStream = null;
                                        FtpWebResponse uploadResponse = null;
                                        try
                                        {
                                            Thread.Sleep(20);
                                            uploadRequest.Credentials = new NetworkCredential(user, pass);
                                            uploadRequest.KeepAlive = false;
                                           
                                            uploadRequest.Method = WebRequestMethods.Ftp.UploadFile;
                                            uploadRequest.UseBinary = true;
                                            uploadRequest.Timeout = 10000000;
                                            byte[] buffer = null;
                                            uploadRequest.Proxy = null;
                                            requestStream = uploadRequest.GetRequestStream();
                                            long bytesToRead = file.ContentLength;
                                            int bytesRead = 0;

                                            while (bytesRead < bytesToRead)
                                            {
                                                buffer = new byte[file.ContentLength];

                                                bytesRead += file.InputStream.Read(buffer, 0, buffer.Length);
                                                if (bytesRead == 0)
                                                    break;

                                                requestStream.Write(buffer, 0, bytesRead);
                                              
                                            }


                                            requestStream.Close();
                                            uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();
                                           
                                        }
                                        catch (UriFormatException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        catch (IOException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        catch (WebException ex)
                                        {
                                            lbl_error.Text = ex.Message;
                                        }
                                        finally
                                        {
                                            if (uploadResponse != null)
                                                uploadResponse.Close();
                                         
                                            if (requestStream != null)
                                                requestStream.Close();
                                        }
      
                                        this.ShowMessage("" + fileName + " Uploaded ", i);

                                    }
                                    else
                                    {
                                        this.ShowMessage(" <font color=red> This is not a Picture File</font/>", i);
                                    }
                                    //}
                                }
                                catch (Exception ex)
                                {
                                    this.ShowMessage("<font color=red> " + fileName + " Not Uploaded <font>", i);
                                }
                            }
                           
                        }
                        else
                        {
                            this.ShowMessage("<font color=red> " + fileName + " File size not more than 6MB</font>", i);
                        }
                      
                    }
                   

                }
               
            }
        }
        catch (Exception ex)
        {
            Response.Redirect("default.aspx");
        }


    }
:((

Thanks..
Posted
Updated 20-Oct-10 2:39am
v2

Sounds like you need to add the following to your Web.config:

XML
<system.web>
    <httpRuntime maxRequestLength="2097151" />
</system.web>


This is the setting that restricts the size of files you can upload. The default setting is 4096. Fine if all you ever upload are small files of less than 4MB. I have set it here to 2097151 - the maximum. That is insanely high. Don't leave it at that unless you have a really, really good reason to do so and really, really need to upload 2 gig files.
 
Share this answer
 
v2
Comments
raju melveetilpurayil 20-Oct-10 8:49am    
Good answer
arun.emm 21-Oct-10 1:53am    
I have already added this in the web.config file..but Still not working.. what do i do?..
hello dear...
I think that this problem is not related to host, but settings (web.config) file
add this attributes in system.web attributes to set max upload file size 10 mb (80mb=80*1024 kb)
<httpRuntime maxRequestLength="10240" executionTimeout="3600"/>
 
Share this answer
 
v3
Comments
arun.emm 21-Oct-10 1:52am    
I have already added this in the web.config file..

<httpruntime maxrequestlength="2097151" executiontimeout="3600">

Still not working.. what do i do?..

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