I have a webpage set up that allows users to upload a file to a server from the fileupload control, which is then saved to the database with the blob file and the file name. What I would like to do now is retrieve this file by selecting a particular value in a dropdown list and clicking on a 'download file' button.
This would then search the database for the ID of the file selected and then throw back the file giving the user the option to 'open, save or cancel'
I have found the following code that retrieves a blob from a database. But this does it only for a specific hardcoded filename. What I have been trying to do is write a stored procedure that takes the ID of the file and returns the BLOB....Its already in the database I just need a little help getting it out now...has anyone any ideas?
SqlDataAdapter da = new SqlDataAdapter("Select * From pub_info", myConnection); SqlCommandBuilder MyCB = new SqlCommandBuilder(da); DataSet ds = new DataSet(); myConnection.Open(); da.Fill(ds, "Pub_info"); DataRow myRow; myRow = ds.Tables["Pub_info"].Rows; byte MyData; MyData = (byte)myRow["logo"]; Response.Buffer = true; //Replace the following commented out line with the lines below for word doc //Response.ContentType = "Image/JPEG"; Response.AddHeader("Content-Disposition", "attachment;filename=blob.doc"); Response.ContentType = "application/msword"; Response.BinaryWrite(MyData); MyCB = null; ds = null; da = null; myConnection.Close(); myConnection = null;
Please provide some suggestions.