hi ,
the below code works well on local server and i'm able to upload file..
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.UsePassive = 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(" This is not a Picture File", i);
}
//}
}
catch (Exception ex)
{
this.ShowMessage(" " + fileName + " Not Uploaded ", i);
}
}
}
else
{
this.ShowMessage(" " + fileName + " File size not more than 6MB", i);
}
}
}
}
}
catch (Exception ex)
{
Response.Redirect("default.aspx");
}
}
But it is not working after the site is hosted on the server.. that is, the file is not uploading.. also it doesn't returns any error.. Am i missing something?.. Pls help me out...
Thanks...
Loading
Posted Oct 15, 2010, 5:23 AM
Please look at the below links ,
http://dotnetslackers.com/Community/blogs/haissam/archive/2008/09/12/upload-large-files-in-asp-net-using-httpmodule.aspx
http://www.codeproject.com/KB/aspnet/uploadlargefilesaspnet.aspx
http://forums.asp.net/t/55127.aspx
http://weblogs.asp.net/jgalloway/archive/2008/01/08/large-file-uploads-in-asp-net.aspx
http://www.obout.com/fup/docum_4.aspx
http://www.infoq.com/news/2008/01/handling-large-uploads
http://www.15seconds.com/issue/071025.htm
Hope this helps you.
Arunkumar EmmPosted Oct 15, 2010, 2:53 AM
Mahesh ChandPosted Oct 14, 2010, 4:11 PM
Posted Oct 14, 2010, 1:53 PM
What you are getting in uploadResponse object?
uploadResponse = (FtpWebResponse)uploadRequest.GetResponse();