嘿傢伙們,試圖清理我最後的帖子,所以在這裏。FTP處理程序頁面,從aspx調用字符串幫助初始化處理程序頁面
我在我的asp.net項目中有一個處理頁面,它試圖處理一個ftp下載請求。
GetImage.ashx.cs
public class GetImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
{
// method for calling PhotoPath from Database.aspx.cs
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri());
// (new Uri) I would like to just store "photopath" in here as it has the ftp plus the filename in it
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("username", "password");
try
{
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
byte[] bytes = new byte[2048];
int i = 0;
MemoryStream mStream = new MemoryStream();
do
{
i = stream.Read(bytes, 0, bytes.Length);
mStream.Write(bytes, 0, i);
} while (i != 0);
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "image/jpeg";
// Response.Headers.Add("Content-Type", "image/jpeg"); this is from the database.aspx page not sure if its correct
context.Response.BinaryWrite(mStream.GetBuffer());
}
catch (WebException wex)
{
}
catch (Exception ex)
{
throw new Exception("An error occurred: " + ex);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
在我的網頁保存我的GridView我有一個方法來提取我的細胞的一個數據,這個單元包含的FTP路徑和文件名像我嘗試在我的圖像控件顯示:
Database.aspx.cs
protected void Page_Load(object sender, EventArgs e){
Response.Headers.Add("Content-Type", "image/jpeg");
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string PhotoPath = "";
// Get the currently selected row. Because the SelectedIndexChanging event
// occurs before the select operation in the GridView control, the
// SelectedRow property cannot be used. Instead, use the Rows collection
// and the NewSelectedIndex property of the e argument passed to this
// event handler.
GridViewRow row = GridView1.Rows[GridView1.SelectedIndex];
PhotoPath = row.Cells[5].Text;
// how do I send photopath to my handler page?
//TextBox1.Text = PhotoPath;
}
}
}
在我的處理程序頁面我想打電話給字符串「PhotoPath」,並把它放在我的ftwwebrequest在我的處理程序頁面:
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(PhotoPath));
香港專業教育學院爲我設置圖像控件的ImageUrl到〜/ GetImage.ashx和將需要一些幫助來從我的數據庫頁面調用處理程序的代碼?
任何人都可以幫忙,因爲我一直堅持這個很長一段時間?
請不要轉發問題。你應該編輯了prev之一。或關閉它。 – 2010-12-05 18:12:36