ちょっと私のASPサイトに画像制御URIがあります。私はFTPダウンロードをセットアップし、それをメモリストリームに保存して画像コントロールに渡そうとしています。FTPメモリストリームと画像コントロール
しかし、成功していない新しいURLは、photoPathを使用できません。ちょうど正しく表示されません。私の "photoPath"は、それを私のprocessrequestに渡そうとしているftpsパス名を保持しています。全く失われた。私が探しているのは、私の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");
存在しません。それは画像制御に???
コードの最初の部分は、グリッドビュー(ftpのパス名とファイル名)のセルの値をとります.2番目の部分は、そのフォトパスをダウンロードしてメモリストリームに保存し、最後の部分はわかりませんそれを私のイメージコントロールに表示する方法です。
エラー行には2つの呼び出しが含まれています。最初にそれを分解し、関連するエラーメッセージを投稿してください。 –
Ok ive編集して私の投稿abit混乱のため申し訳ありません。 –