Hrvoje

Hrvoje

  • NA
  • 47
  • 0

image upload

Jun 16 2009 2:36 AM

I'm using this code to upload a file to server, but it doesn't work for image file.
What should be changed?
 
FileInfo uploadFile = new FileInfo(cbFile.Text);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp:address" +
uploadFile.Name);
request.Proxy =
null;
request.Method =
WebRequestMethods.Ftp.UploadFile;
request.Credentials =
new NetworkCredential(username, password);
Stream ftpStream = request.GetRequestStream();
FileStream fStream = File.OpenRead(cbFile.Text);
int length = 1024;
byte[] buffer = new byte[length];
int byteRead = 0;
do
{
byteRead = fStream.Read(buffer,0,length);
ftpStream.Write(buffer,0,byteRead);
}
while
(byteRead !=0);
fStream.Close();
ftpStream.Close();

Answers (1)