using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class texting : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string JobCategory = Page.RouteData.Values["job_category"].ToString();
string JobName = Page.RouteData.Values["job_name"].ToString();
//string JobName = Request.QueryString["job_name"];
if (!string.IsNullOrWhiteSpace(JobName))
{
ShowDetails(JobName);
}
}
private void ShowDetails(string JobName)
{
SqlDataSourcejobdetails.SelectCommand = "SELECT * FROM [latestsarkarijobdb].[dbo].[TBL_jobdetails] where job_name ='" + JobName + "' ";
}
protected void DownloadFile(object sender, EventArgs e)
{
string JobName = Page.RouteData.Values["job_name"].ToString();
byte[] bytes;
string fileName, contentType;
string constr = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "select notification_name, notification_data, notification_type from TBL_jobdetails where job_name=@job_name";
cmd.Parameters.AddWithValue("@job_name", JobName);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
bytes = (byte[])sdr["notification_data"];
contentType = sdr["notification_type"].ToString();
fileName = sdr["notification_name"].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();
}
}
my code is working but this is directly download not open in new tab so please help me in this code