使用C#ASP.Net和Visual Studio 2012最终版。来自ftp地址的asp.net图像源
我从表单中重新使用了一些代码。从FTP服务器下载图像。
public class FTPdownloader
{
public Image Download(string fileName, string ftpServerIP, string ftpUserID, string ftpPassword)
{
FtpWebRequest reqFTP;
Image tmpImage = null;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileName));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
tmpImage = Image.FromStream(ftpStream);
ftpStream.Close();
//outputStream.Close();
response.Close();
}
catch (Exception ex)
{
//MessageBox.Show(ex.Message);
}
return tmpImage;
}
}
伟大的工程,我所做的就是在我的窗体上这样称呼它。
imgPart.Image = ftpclass.Download("" + "" + ".jpg", "address/images", "user", "pass");
现在这对winforms很好用。我的新项目是一个asp.net webform。我需要它来做同样的事情。 我已经重新使用这段代码,似乎没问题,但是当我调用img.Image的方法时,我发现img.Image在asp.net中不存在。 基本上我正在返回一个图像,我能找到的最接近的是一个Img.ImageUrl,当然这是一个字符串。
所以即时通讯希望这是这个代码稍微改变一些东西在呼叫我缺少(新的asp.net)。
任何帮助将是伟大的。多谢你们!
您是否在文件顶部的引用中使用了“System.Drawing”? – Scott
是的引用它在顶部对不起,我没有把它放在 – lemunk
当你试图编译代码时,你会得到什么错误? – Scott