简体   繁体   中英

How to upload image from windows form picturbox to FTP server?

I have a form with a picturebox. At first i load the picturebox with picture from my local pc. Now i want to upload the picture to a ftp server.

I don't understand how to get the filepath of picturebox. Or is there any other way?

public void UploadImage(PictureBox image, string filename)
{
    using (WebClient client = new WebClient())
    {
   client.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
 client.UploadFile("ftp://127.0.0.1/Image/",WebRequestMethods.Ftp.UploadFile);

   }

}

You need to get first file path of image that is in your picture box

string filepath = image.ImageLocation;

And then pass this path to WebClient.UploadFile like

public void UploadImage(PictureBox image, string filename)
{
    string filepath = image.ImageLocation;     //<= Get image path 

    using (WebClient client = new WebClient())
    {
        client.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
        client.UploadFile("ftp://127.0.0.1/Image/", filepath);    //<= Pass this path here

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM