簡體   English   中英

如何從Windows窗體picturbox上傳圖像到FTP服務器?

[英]How to upload image from windows form picturbox to FTP server?

我有一個帶有圖片框的表格。 首先,我用本地計算機上的圖片加載圖片框。 現在,我想將圖片上傳到ftp服務器。

我不明白如何獲取圖片框的文件路徑。 還是還有其他方法?

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);

   }

}

您需要獲取圖片框中圖片的第一個文件路徑

string filepath = image.ImageLocation;

然后將此路徑傳遞給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