Всякий раз, когда я нажимал на кнопку View Link, она открывала вложение в формате pdf на той же странице, я хочу открыть его в новой вкладке и ограничить пользователя, чтобы он не мог быть загружен в любом случае, пожалуйста, помогите мне.
метод кнопки ссылки, когда я нажимаю на вид, он вызывает этот метод
protected void lnk_Click(object sender, EventArgs e)
{
GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer;
string DocumentCode = grdrow.Cells[1].Text;
string TextInGrid = grdrow.Cells[0].Text;
Regex re = new Regex("[;\\\\39/#:*?\"<>|&']");
string AttachmentName = re.Replace(TextInGrid, " ");
string DocID = grdrow.Cells[3].Text;double num;
if (double.TryParse(DocID, out num))
{
byte[] bytes;
string fileName, ContentType, DocExtension;
string constr = ConfigurationManager.ConnectionStrings["QMSConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT DivisionalDocID, AttachmentContent,
AttachmentName,AttachmentContentType,DocExtension
FROM DivisionalDocuments
WHERE DocumentCode = @DocumentCode
AND DivisionalDocID = @DocID";
cmd.Parameters.AddWithValue("@DocumentCode", DocumentCode);
cmd.Parameters.AddWithValue("@DocID", DocID);
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
sdr.Read();
fileName = sdr["AttachmentName"].ToString();
FileNameWithOutCharchters = fileName.Replace(",", "");
ContentType = sdr["AttachmentContentType"].ToString();
DocExtension = sdr["DocExtension"].ToString();
}
con.Close();//close the connection
}
}
Response.Clear();
Response.Buffer = true;
Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = ContentType;
//i use inline here to so the attachment will not be
//downloaded
// You really posted only code, without a line to explain what you are trying to achieve, why it doesn't work, and which error messages you eventually got.
Response.AppendHeader("Content-Disposition", "inline; filename=" + FileNameWithOutCharchters + DocExtension);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
else
{
}
Спасибо,