TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Arunkumar Emm
NA
65
0
file not uploading
Oct 14 2010 1:07 PM
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(" <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");
}
}
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...
Reply
Answers (
4
)
Read large files in C#
Google Map not working in IIS