使用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