Hi guys, I just want to ask some help
I added a Download Button in every row of my Gridview. Its function is to download the Binary File of the corresponding row.
Whenever i run it it gives me the error "Object reference not set to an instance of an object."
Pls help me im just a beginner @_@
Heres my code behind:
protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
String[] fileInfo = e.CommandArgument.ToString().Split(new char[] { ',' });
int DocID = Int32.Parse(fileInfo[0]);
String FileName = fileInfo[0];
SqlConnection conn = new SqlConnection("My connection String");
SqlCommand cmd = new SqlCommand("SELECT BinaryData from BinaryTable WHERE DocID = @DocID");
cmd.Parameters.AddWithValue("@DocID", DocID);
cmd.Connection = conn;
conn.Open();
byte[] BinaryData = (Byte[])cmd.ExecuteScalar();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName + ".zip");
Response.BinaryWrite(BinaryData);
}
}
}
Any help would be highly appreciated. Thanks!
by the way, im using visual studio 2005 and sql server 2005