Anuradha Chavan

Anuradha Chavan

  • NA
  • 37
  • 16.2k

open a file from database to new tab

Nov 20 2013 1:10 AM
Hello,
I am working on a website. In this, I have to display a name of file uploaded by admin(not its file name) as link. when a user click on link, it will open saved file from database(pdf files saved as binary files).
I have used a datalist as-


<asp:DataList ID="DL_Circular" runat="server" DataKeyField="ID"
style="z-index: 1; left: 0px; top: 17px; position: absolute; height: 271px; width: 498px"
Width="498px">
<ItemTemplate>
<asp:LinkButton ID="lnkName" runat="server"
CommandArgument='<%#Eval("ID") %>' Text='<%#Eval("Name")%>'>
</asp:LinkButton>
<br />
</ItemTemplate>
</asp:DataList>



and in .cs file code is

protected void Bind_DataList()
{
string strCon = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(strCon);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from Orders_Table order by ID desc", con);
DataTable dt = new DataTable();
PagedDataSource pd = new PagedDataSource();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
pd.DataSource = dt.DefaultView;

DL_Circular.DataSource = pd;
DL_Circular.DataBind();

}

else
{
DL_Circular.Visible = false;

}
con.Close();
}


I am trying to give a onclick event, that will conver binary to pdf format and open pdf file in new tab. But it fails.

Please help me.
Thank you,

Answers (2)