views:

140

answers:

1

We have encountered this difference in file creation while using a HttpHandler Versus a Code Behind Aspx page.

We are reading a saved jpg/png picture as byte array from a 'Image' field in sql server database and create a physical file in the server.

Both the Aspx Page and Httphandler use the same code pasted below.

//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 

After the file is created, it is viewable as a jpg/png Image only in Aspx Code Behind. While in case of HttpHandler it is not a valid Image.

Any ideas for this behavior/missing link/resolution steps will be helpful.

Thank you.

A: 

Finally isolating different steps the problem was identified to be the data being stored into Database Table.

The way to eliminate this issue was during upload of file, Create a physical file on the server local system. Read this file into a byte array and store into the Database Table. (Could be Encoding Issue)

kanchirk