嘿我有一個圖像控制uri在我的asp網站我試圖設置一個ftp下載並將其存儲在內存流然後傳遞給圖像控制。FTP內存流和圖像控制
但沒有成功,新的uri無法使用photoPath,它只是看起來不對。我的「photoPath」保存了ftps路徑名,試圖將其傳遞給我的processrequest。完全失去。我所要做的就是在選擇我的gridview時,使用ftp路徑名+文件名看起來像這樣:ftp://192.168.1.2/Jelly.jpg
已完成並已將其存儲在字符串名稱PhotoPath中。然後做一個ftp請求下載它存儲在一個內存流然後將其放入一個圖像控件。應該不是很難吧?
代碼:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) {
string PhotoPath = "";
GridViewRow row = GridView1.Rows[GridView1.SelectedIndex];
PhotoPath = row.Cells[5].Text;
}
public void ProcessRequest (HttpContext context) {
// error on this line due to photopath
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(PhotoPath));
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.Clear();
context.Response.ClearHeaders();
context.Response.ClearContent();
context.Response.ContentType = "image/jpeg"; // unsure of this line
context.Response.BinaryWrite(mStream.GetBuffer());
}
catch (WebException wex) {
//throw new Exception("Unable to locate or access your file.\\nPlease try a different file.");
}
catch (Exception ex) {
throw new Exception("An error occurred: " + ex);
}
}
public bool IsReusable {
get { return false; }
}
此行包含錯誤:PhotoPath不會在當前的背景下存在
public void ProcessRequest (HttpContext context){
// error on this line due to photopath
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(PhotoPath));
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential("username", "password");
一旦我做了這一點,我需要找到一種方法,通它的圖像控制?
代碼的第一部分需要在我的gridView中的單元格的值(第二部分是我的方法來下載該photopath並將其存儲在內存流中,我的最後一部分我不知道如何做就是在我的圖像控制中顯示它。
錯誤行包含2個調用。首先將其分解併發布相關的錯誤消息。 – 2010-12-05 14:20:06
好的,我編輯了我的帖子高級對不起,爲混亂。 – 2010-12-05 14:50:38