byte[] content = sdr["Content"] as byte[];
private void btnDownload_Click(object sender, EventArgs e) { try { using (SqlCommand cmd = new SqlCommand("SelectFile", Conn)) { cmd.CommandType = CommandType.StoredProcedure; Conn.Open(); cmd.Parameters.Add("@FileName", SqlDbType.VarChar).Value = "1.txt"; string Ext = Path.GetExtension("1.txt"); SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (sdr.HasRows) { sdr.Read(); byte[] content = sdr["Content"] as byte[] ; if (fdDownload.ShowDialog() == DialogResult.OK) { FileStream fs = new FileStream(fdDownload.FileName + Ext , FileMode.CreateNew, FileAccess.Write); fs.Write(content, 0, content.Length); fs.Flush(); fs.Close(); } lblMessage.ForeColor = System.Drawing.Color.Green; lblMessage.Text = "File Downloaded Successfully"; Conn.Close(); } else { lblMessage.ForeColor = System.Drawing.Color.Green; lblMessage.Text = "File not Downloaded Successfully"; Conn.Close(); } } } catch (SqlException sqlEx) { lblMessage.ForeColor = System.Drawing.Color.Red; lblMessage.Text = "File not Downloaded Successfully"; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)