The screen shot below is from an ASP.NET Upload control that was used to load files to a database. The grid below the control shows what items were uploaded.
On another page I list all the documents that were load for the user to select to print.
Code to take the uplaoded file and make it into a Byte Array. The variable DocumentOBJ contains the uploaded file which can then be saved to the database. Note: If you save the object to the database you need to save the FileType which can be pulled from the FileUpload.PostedFile.FileType property.
The code below takes the object above (or from a table) and renders it to the browser to open.
-- Get byte array from uploaded file
byte[] DocumentOBJ = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile uploadedImage = FileUpload1.PostedFile;
FileUpload1.PostedFile.InputStream.Read(DocumentOBJ, 0, FileUpload1.PostedFile.ContentLength);
public static void RenderObjectToBrowser(string fileName, string fileType, byte[] obj)
{
HttpContext CTX = HttpContext.Current;
//Get the Proposal Row
AQP.DAL.Proposal prop = new DAL.Proposal();
AQP.DAL.dsProposal.QP_MASTERRow row = prop.GetProposalMasterRow(1011, 1);
MemoryStream MemStream = new MemoryStream(obj);
CTX.Response.ContentType = fileType;
CTX.Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
CTX.Response.AddHeader("Content-Length", MemStream.Length.ToString());
//CTX.Response.Clear();
//CTX.Response.Buffer = true;
CTX.Response.BinaryWrite(obj.ToArray());
}