locked
Open file in another window (browser) RRS feed

  • Question

  • Hi

    I written code like below for open save dialog box in asp.net

    FileStream fs;

    String strFileName = @"D:\Sample.doc\";

    fs = File.Open(strFileName, FileMode.Open);

    Byte[] buffer = new byte[1048576];

    long bytBytes = fs.Length;

    fs.Read(buffer, 0, 1048576);

    fs.Close();

    Response.AddHeader("Content-disposition", "attachment; filename=" + strFileName);

    Response.ContentType = "application/octet-stream";

    Response.BinaryWrite(buffer);

    Response.End();

    While click on open is opening in same window, but i want to open in another window or respective file format exe (means like in word, notepad, pdf etc)

    Please suggest any idea.


    jaya
    Tuesday, April 20, 2010 6:21 AM

Answers

  • If you want the file to be opened in the appropriate application,

    Response.ContentType = "application/octet-stream";

    should have the right value like for .xls it is application/vnd.xls

     

     

     


    ============================================================ Please do not forgot to mark it as an ansswer if it is. Thanks Gags
    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 6:29 AM
  • or incase you want to open in another window fire the same code on javascript call rather than post back and use window.open method
    Manish Sati
    • Proposed as answer by Shah Bhavik Tuesday, April 20, 2010 6:50 AM
    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 6:40 AM
  • You may repost at http://forums.asp.net/ where you will get better answers from experts there.

    Thank you.

    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 8:14 AM

All replies

  • If you want the file to be opened in the appropriate application,

    Response.ContentType = "application/octet-stream";

    should have the right value like for .xls it is application/vnd.xls

     

     

     


    ============================================================ Please do not forgot to mark it as an ansswer if it is. Thanks Gags
    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 6:29 AM
  • or incase you want to open in another window fire the same code on javascript call rather than post back and use window.open method
    Manish Sati
    • Proposed as answer by Shah Bhavik Tuesday, April 20, 2010 6:50 AM
    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 6:40 AM
  • You may repost at http://forums.asp.net/ where you will get better answers from experts there.

    Thank you.

    • Marked as answer by Harry Zhu Monday, April 26, 2010 3:14 AM
    Tuesday, April 20, 2010 8:14 AM