Skip to content

Image upload

Hrvoje

Asked Jun 15, 2009, 10:36 PM EDT1 answer
Share
LinkedInX
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();

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I tried with jpg file and  it worked fine.
    0