![](/img/trans.png)
[英]How to get an image to display in Picturbox from a Listbox selected item
[英]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.