使用WinSCP .NET程序集将图片从FTP加载到PictureBox [英] Load picture from FTP to PictureBox with WinSCP .NET assembly
问题描述
我正在使用WinSCP .NET程序集通过FTP传输文件.几天前,我开发了新的模块来显示PictureBox
控件中的图片.我想要实现的是在列表框中或其他任何位置列出图片的路径,然后单击此路径以在PictureBox
中打开图片.关键是图片位于我的FTP的远程位置上,我不知道是否可以使用WinSCP(FTP)使用获取其路径,然后使用这些路径在PictureBox
中显示给定的图片.有人知道有可能吗?
I am using WinSCP .NET assembly to transfer files by FTP. Couple days ago I developed new module to show pictures in PictureBox
control. What I would like to achieve is to list picture's paths inside listbox or whatever else and then when click on this path to be able to open the picture in PictureBox
. The point is pictures are on remote location on my FTP and I have no idea is it possible using WinSCP (FTP) to use get their path and then using the paths to show up given picture inside PictureBox
. Anyone has idea is it possible or not?
推荐答案
您必须将文件下载到本地临时文件,然后将其加载到图片框中.您不能直接加载远程文件.
You have to download the file to a local temporary file and load the file to the picture box. You cannot load the remote file directly.
' Unique temporary path
Dim tempPath As String = Path.GetTempFileName()
' Download the image
session.GetFiles(RemotePath.EscapeFileMask(remoteImagePath), tempPath).Check()
' Load tempPath to picture box
<your code here>
' Delete the temporary file
File.Delete(tempPath)
(我不使用VB.NET,因此语法可能不是100%正确)
这篇关于使用WinSCP .NET程序集将图片从FTP加载到PictureBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!