even i am facing the same problem and after trying your solution also i am getting the (open/Save dialog) when i try to open a pdf file from DB. can you help me on this...
my code is...
if (Request.QueryString["QuestionID"] !=
null)
{
long FileID =
long.Parse(Request.QueryString["QuestionID"]);
DataTable dtbl_Attachment = Table2.Select(FileID);
string sContentType=string.Empty;
string sHeader1 =
string.Empty;
string sHeader2 =
string.Empty;
if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("PDF"))
sbadriprasad
Member
274 Points
305 Posts
Re: Problem Streaming PDF File to IE Browsers
Sep 03, 2007 05:58 AM|LINK
hi,
even i am facing the same problem and after trying your solution also i am getting the (open/Save dialog) when i try to open a pdf file from DB. can you help me on this...
my code is...
if (Request.QueryString["QuestionID"] != null){
long FileID = long.Parse(Request.QueryString["QuestionID"]); DataTable dtbl_Attachment = Table2.Select(FileID); string sContentType=string.Empty; string sHeader1 = string.Empty; string sHeader2 = string.Empty; if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("PDF")){
sContentType = "application/octet-stream";sHeader1 =
"content-disposition"; sHeader2 = "inline; filename=MyPDF.PDF";}
else if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("DOC")){
sContentType =
"application/msword"; sHeader1 = "content-disposition";sHeader2 = "inline; filename=MyDoc.DOC";}
else if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("XLS")){
sContentType =
"application/x-excel"; sHeader1 = "content-disposition";sHeader2 = "inline; filename=MyExcel.XLS";}
else if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("TXT")){
sContentType =
"text/plain"; sHeader1 = "content-disposition";sHeader2 = "inline; filename=MyTXT.TXT";}
else if (dtbl_Attachment.Rows[0]["FileType"].ToString().ToUpper().Equals("RTF")){
sContentType =
"application/rtf"; sHeader1 = "content-disposition";sHeader2 = "inline; filename=MyRTF.RTF";}
elsesContentType =
"application/pdf"; byte[] bData = ((byte[])dtbl_Attachment.Rows[0]["FileContent"]);Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = sContentType;
Response.AddHeader(sHeader1, sHeader2);
Response.AddHeader("content-length", bData.Length.ToString());Response.Charset =
"";Response.BinaryWrite((
byte[])dtbl_Attachment.Rows[0]["FileContent"]);Response.Flush();
Response.End();
}
}