如何在WindownForm中将图像URL(ftp)从服务器绑定到图片Edit(或pictureBox) [英] How to binding image url (ftp) from server to picture Edit (or pictureBox) in WindownForm
问题描述
我有问题从服务器(有链接)到绑定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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!