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();
 
            }

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();
 
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.