0
我們在使用HttpHandler與代碼隱藏Aspx頁面時遇到了這種文件創建的差異。Httphandler版本Aspx代碼在寫入圖像文件後
我們正在讀取一個保存的jpg/png圖片作爲字節數組,來自sql server數據庫中的'Image'字段,並在服務器中創建一個物理文件。
Aspx頁面和Httphandler都使用下面粘貼的代碼。
//Begin
int docID = Convert.ToInt32(Request.QueryString["DocID"]);
var docRow = documentDB.GetDocument(docID);
// Retrieve the physical directory path for the Uploads subdirectory
string destDir = Server.MapPath("../../Uploads").ToString() + "\\";
string strFileName = destDir + DateTime.Now.ToFileTime() + "_" + docRow.DocName.ToString();
FileStream fs = new FileStream(strFileName, FileMode.CreateNew, FileAccess.Write);
fs.Write(docRow.DocData, 0, docRow.DocData.Length);
fs.Flush();
fs.Close();
// End
該文件創建後,它可以作爲jpg/png圖像僅在Aspx代碼隱藏中可見。 而在HttpHandler的情況下,它不是一個有效的圖像。
此行爲的任何想法/缺少鏈接/解決步驟將有所幫助。
謝謝。