简体   繁体   English

如何从Windows窗体picturbox上传图像到FTP服务器?

[英]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. 现在,我想将图片上传到ftp服务器。

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 然后将此路径传递给WebClient.UploadFile

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

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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