hello ,
i have problem with this code while press linkbutton download i get this error
Exception Details: System.FormatException: تنسيق سلسلة الإدخال غير صحيح.
int id = int.Parse((sender as LinkButton).CommandArgument);
I am using this in normal table not GV, from GV its working very well.
Getting name by user logged in and he get all info by SQL DB.
protected void DownloadFile(object sender, EventArgs e)
{
int id = int.Parse((sender as LinkButton).CommandArgument);
byte[] bytes;
string fileName, contentType;
string constr = ConfigurationManager.ConnectionStrings["kankonConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select Namefile, backupmyfile, ContentType from Table_infoname where Id=@Id";
cmd.Parameters.AddWithValue("@Id", id);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytes = (byte[])sdr["backupmyfile"];
contentType = sdr["ContentType"].ToString();
fileName = sdr["Namefile"].ToString();
}
con.Close();
}
}
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();
}
<asp:LinkButton ID="lnkDownload" runat="server" Text="Download" OnClick="DownloadFile" CommandArgument='<%# Eval("Id") %>' Visible='<%# !string.IsNullOrEmpty(Eval("Namefile").ToString()) ? true : false %>'>
</asp:LinkButton>