unable to upload larger file after hosting on the server

Oct 20 2010 8:13 AM
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 locallt , 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");
        }


    }

Answers (1)