Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8068597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:44:35+00:00 2026-06-05T12:44:35+00:00

I need the browser to open file types it understands directly in the browser

  • 0

I need the browser to open file types it understands directly in the browser (i.e. no “Open/Save/Cancel” dialog.

Here’s my code, which currently works great!…except that every file pops up the dialog box and doesn’t directly open the file:

string filePath = Path.Combine(WebConfigurationManager.AppSettings["NewsAttachmentPath"], context.Request.QueryString["FileName"]);
byte[] bytes = System.IO.File.ReadAllBytes(filePath);
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.Cache.SetCacheability(HttpCacheability.Private);
context.Response.Expires = -1;
context.Response.Buffer = true;
context.Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"", "inline", context.Request.QueryString["FileName"]));
context.Response.BinaryWrite(bytes);
context.Response.End();

As you can see, even when I change the Content-Disposition to “inline”, it still prompts for download. This is with files that I know my browser understands. In other words, I can go to some random site and click a PDF, and it will open in the browser. My site will make me save it in order to view it.

Pre-emptive answer to “why do you wanna use application/octet-stream?” Because I don’t want to create a handler for each single file type. If this is mistaken, please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:44:38+00:00Added an answer on June 5, 2026 at 12:44 pm

    You do not need to create a handler per file type. You just change the line:

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

    to be:

    string contentType = //your logic here, possibly many lines in a separate method
    context.Response.ContentType = contentType;
    

    But no: you can’t “inline” an application/octet-stream. That means “here’s some bytes, but I don’t know what they are”. The browser can’t do much with that, other than save it somewhere, hence a download prompt. You can use content-disposition to suggest a filename, though.

    The browser does not work on file extensions – it works on content-type. So: you need to report the correct content-type in your response. This might mean writing a switch / lookup based on the file extension that you know, or it might mean storing the explicit content-type separately as metadata along with the file information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to open pdf file into browser without Adobe Reader. Is there any
I have a .sdb database file which I need to open. It's the database
I need the browser to cache a large, mostly static .php file. I open
I need to open a second browser window or tab, but it must have
I just started with WPF and just now worked with open file dialog to
I have file in the form of binary array and i need the browser
I am trying to add Images using open file dialog and folder browse dialog
Is there a way to open file dialog box to upload a file, on
I need a cross browser way of capturing the right mouse click, preventing the
I need a cross-browser compatible plugin for textrea to be auto growing and shrinking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.