using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class downloadfile : System.Web.UI.Page { string Id; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["fuzzyconnection"]); con.Open(); Id = (string)Session["filenam"]; SqlCommand cmd = new SqlCommand("select * from ownerfiles where filenam = '" + Id + "'", con); //cmd.Parameters.Add("@FileId",SqlDbType.Int).Value=1; DataTable dt = GetData(cmd); if (dt != null) { download(dt); } } } private DataTable GetData(SqlCommand cmd) { DataTable dt = new DataTable(); SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["fuzzyconnection"]); SqlDataAdapter sda = new SqlDataAdapter(); cmd.CommandType = CommandType.Text; cmd.Connection = con; try { con.Open(); sda.SelectCommand = cmd; sda.Fill(dt); return dt; } catch { return null; } finally { con.Close(); sda.Dispose(); con.Dispose(); } } private void download(DataTable dt) { if (dt.Rows.Count > 0) { Byte[] bytes = (Byte[])dt.Rows[0]["files"]; Response.Buffer = true; Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); //Response.ContentType = dt.Rows[0]["Ftype"].ToString(); Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["filenam"].ToString()); //Response.BinaryWrite("<script type='text/javascript'> <embed src='bytes' style=width:300px; height:200px;> </embed> </script> "); Response.ContentType = "application/msword"; Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } } }
Id = (string)Session["filenam"];
DataTable dt = GetData(cmd);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)