open file without saving

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lisles
    New Member
    • Jan 2010
    • 40

    open file without saving

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

    im coding in c#
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Well, you are sending the user some sort of file.
    The browser is going to receive this file and some header information that contains data about what the file is. If the browser knows how to handle the file (for example it knows how to open a .pdf file because there is a plugin installed into the browser) then it will open it...if the browser doesn't know how to handle the file (doesn't have a plugin for that type) then it will give the user the option to save it or open it with an application installed on the computer.

    So, you should specify what type of file you are sending to the browser. You do this by changing the Response.Conten tType to the type of file that you are sending (right now you are specifying that you are sending a file of type "applicatio n/Octet-stream"...whate ver that is).

    -Frinny

    Comment

    • lisles
      New Member
      • Jan 2010
      • 40

      #3
      i tried puttin a seperate function for each extension also like pdf,xls and doc but it still asks if i wanna save...is it not possible to open the file directly?

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        It depends on whether or not the browser knows how to open the file.

        If the browser doesn't know how to handle the file then it will give the user the option to save it to their computer so that they can open it with a program will work with the file.

        Browsers know how to open .pdf files if the have the Adobe reader plugin installed.

        Browsers do not know how to open xls or doc files...therefo re the user must save them to their computer and open them with Excel or Word.

        -Frinny

        Comment

        Working...