0

im trying to open a document...but every time i get a dialoge box asking if i want to pen,save or cancel.i just want to open the document.can someone tell me wot im doing wrong?here's my code

if (objView.extension == ".pdf" || objView.extension == ".xls" || objView.extension == ".xlsx" || objView.extension == ".doc" || objView.extension == ".docx")
            {
                System.Data.DataSet dsImg = new System.Data.DataSet();
                dsImg = objView.getBinaryData();
                Response.ContentType = "application/Octet-stream";
 
                Response.AddHeader("content-disposition",
                                               "attachment;filename="+ filename);
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
 
                foreach (System.Data.DataRow dr in dsImg.Tables[0].Rows)
                {
                    Response.BinaryWrite((byte[])dr[0]);
                }
 
                dsImg.Dispose();
                objView.Close();
 
                Response.End();
 
            }
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by rohand
0

change your Response.AddHeader() with below modified : need to use inline instead of attachment.

Response.AddHeader("content-disposition","inline;filename="+ filename);

Try it and let us know..

im trying to open a document...but every time i get a dialoge box asking if i want to pen,save or cancel.i just want to open the document.can someone tell me wot im doing wrong?here's my code

if (objView.extension == ".pdf" || objView.extension == ".xls" || objView.extension == ".xlsx" || objView.extension == ".doc" || objView.extension == ".docx")
            {
                System.Data.DataSet dsImg = new System.Data.DataSet();
                dsImg = objView.getBinaryData();
                Response.ContentType = "application/Octet-stream";
 
                Response.AddHeader("content-disposition",
                                               "attachment;filename="+ filename);
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
 
 
                foreach (System.Data.DataRow dr in dsImg.Tables[0].Rows)
                {
                    Response.BinaryWrite((byte[])dr[0]);
                }
 
                dsImg.Dispose();
                objView.Close();
 
                Response.End();
 
            }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.