I've been searching the web now for a couple of hours. Although it seems very easy to upload a blob file to a sql database, it's a nightmare trying to download it again.
I have a gridview displaying records. The grid view has a linkbutton which I want to use to download a blob file wich is saved in the same table as where the gridview is loading its data from. I'm passing the records id to my code-behind function with the onclick event.
here is my code behind for the on click event
protected void Downloadbutton_Click(Object sender, CommandEventArgs e)
{
string reqid = e.CommandArgument.ToString();
using (SqlConnection connection = new SqlConnection("ConnectionString"))
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select Attached_File_Name from ABSENCE_REQUEST where Request_ID = @Request_ID";
cmd.Connection = connection;
cmd.Parameters.AddWithValue("@Request_ID", Convert.ToInt32(20057));
byte[] buffer = (byte[]) cmd.ExecuteScalar();
using (FileStream fs = new FileStream(@"C:\test.pdf", FileMode.Create))
{
fs.Write(buffer, 0, buffer.Length);
}
}
}
I know that in my code I actually set a download location for the file. But how can I change it so the user will be asked where to save the file?