hello ,
From this [Solved] ASP.Net Download file Error: Invalid attempt to read when no data exists
How i can hide the text download if there is no file upload?
i mean when i search user data if the user not have file upload, i want hide the text download.
protected void DownloadFile(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
byte[] bytes = null;
string fileName = "", contentType = "";
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Namefile, backupmyfile, ContentType from Table_infoname where Id=@Id";
cmd.Parameters.AddWithValue("@Id", hdnflddownload.Value);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr.Read())
{
bytes = (byte[])sdr["backupmyfile"];
contentType = sdr["ContentType"].ToString();
fileName = sdr["Namefile"].ToString();
}
}
con.Close();
}
}
if (bytes != null)
{
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
}