如何在WindownForm中将图像URL(ftp)从服务器绑定到图片Edit(或pictureBox)

编程入门 行业动态 更新时间:2024-10-28 10:26:43
本文介绍了如何在WindownForm中将图像URL(ftp)从服务器绑定到图片Edit(或pictureBox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有问题从服务器(有链接)到绑定pictureEdit获取图像。 $ a函数创建PathFile(我有路径文件(ftp:// ....) )

I am have a problem to get image from server (have link) to binding pictureEdit. a function Create PathFile ( I have path file (ftp://....))

public string CreatePathFile(string fileName, string subFolder) { string localPath = string.Empty; try { System.Configuration.Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string ftp_host = configuration.AppSettings.Settings["FTP_Host"].Value.ToString(); string ftp_homedir = configuration.AppSettings.Settings["FTP_HomeDir"].Value.ToString(); string ftp_username = configuration.AppSettings.Settings["FTP_Username"].Value.ToString(); string ftp_password = configuration.AppSettings.Settings["FTP_Password"].Value.ToString(); string temp_location = System.IO.Path.GetTempPath(); System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(temp_location); if (!System.IO.Directory.Exists(temp_location)) { System.IO.Directory.CreateDirectory(temp_location); } WebClient request = new WebClient(); request.Credentials = new NetworkCredential(ftp_username.Normalize(), ftp_password.Normalize()); string pathFile = "ftp://"; if (String.IsNullOrEmpty(ftp_homedir)) { if (String.IsNullOrEmpty(subFolder)) { pathFile += ftp_host; } else { pathFile += ftp_host + "/" + subFolder; } } else { if (String.IsNullOrEmpty(subFolder)) { subFolder = ftp_homedir; } else { subFolder = ftp_homedir + "/" + subFolder; } pathFile += ftp_host + "/" + subFolder+ "/" + fileName; } localPath = pathFile; } catch (Exception ep) { MessageBox.Show("ERROR: " + ep.Message.ToString()); } return localPath; } }

和绑定到pictureBox的函数

and a function binding to pictureBox

public void SetPictureProduct(string filename) { string link=CreatePathFile(filename, "Products"); //have link: etc: ftp://119.79.35.120:990/med.template/TANMY_TEMPLATE/Products/0501010012.01.03.png if (!string.IsNullOrEmpty(link)) { formPic.ImageLocation = link; //formPic: name of pictureBox } }

结果:远程服务器返回错误:( 530)未登录。 我可以将图像上传到服务器但我无法从服务器加载到pictureEdit。 你能帮帮我吗?非常感谢。 Dev 9.3.3

Result: The remote server returned an error: (530) Not logged in. I can upload image to sever but I can't load from server to pictureEdit. Can you help me? Many Thanks. Dev 9.3.3

推荐答案

Hello v-bui,

Hello v-bui,

尝试将用户名和密码添加到您的ftp网址。格式如下。

Try to add username and password to your ftp url. The format like below.

ftp://user:password@host:port/path

组件遵守以下规则:

  • 用户:主机上的用户名(用户ID)。
  • 密码: 与用户名对应的密码;注意:如果网址中的用户名和密码字段包含字符:或@或/,则必须对该字符进行编码。
  • 主机:网络主机的完全限定域名或其IP地址。
  • 端口:要连接的端口号;它被省略,默认为21。
  • 路径:形式为cwd1 / cwd2 / ... / cwdN / name的路径规范。
  • user: a user name (user id) on the host.
  • password:the password corresponding to the user name; note: if the user and password field in a URL contains character : or @ or /, the character must be encoded.
  • host: the fully qualified domain name of a network host, or its IP address.
  • port: the port number to connect to; it omitted, defaults to 21.
  • path:path specification of the form cwd1 / cwd2 / ... / cwdN / name.
  • 尝试下面的网址。

    ftp://username:password@119.79.35.120:990/med.template/TANMY_TEMPLATE/Products/0501010012.01.03.png

    祝你好运,

    Neil Hu

    更多推荐

    如何在WindownForm中将图像URL(ftp)从服务器绑定到图片Edit(或pictureBox)

    本文发布于:2023-11-09 17:21:02,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1572971.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:绑定   中将   图像   服务器   如何在

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!