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

  • Home
  • SEARCH
  • 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 8393393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:46:19+00:00 2026-06-09T19:46:19+00:00

I have an MVC3 app that allows the user to dowload a file to

  • 0

I have an MVC3 app that allows the user to dowload a file to their hard drive or view it in a browser. The file is stored on a filesher thats not accessible to the internet. So the file’s byte array is stored in memory and then sent to the browser like this:

            /// <summary>
    /// overrides actionresult method so document can be viewed in browser window
    /// </summary>
    /// <param name="context"></param>
    public override void ExecuteResult(ControllerContext context)
    {
        // get current context and set values
        var response = context.HttpContext.Response;
        response.Clear();
        response.BufferOutput = false;   // to prevent buffering 
        response.Cache.SetCacheability(HttpCacheability.NoCache);
        response.ContentType = ContentType;
        response.AddHeader("Content-Length", Length.ToString());

        var ext = Path.GetExtension(FileName);

        if (!Show)
        response.AddHeader("content-disposition", "attachment; filename=\"" + FileName+ "\"");

        response.ContentEncoding = System.Text.Encoding.UTF8;

        var stream = new MemoryStream(ContentBytes);
        stream.WriteTo(response.OutputStream);
        stream.Dispose();

    }

I cant view pdfs for some reason. I can download them but not view them. Im attaching a sample project here showinbrowser.zip. Its VS2010 sp1. Can someone show me how to display a PDF file in a new browser window/tab thats stored in memory? Thanks

  • 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-09T19:46:20+00:00Added an answer on June 9, 2026 at 7:46 pm

    Why not use the Controller.File method which handles this for you ?

    public ActionResult _ShowDocument(string id)
    {
      byte[] fileData=GetByteArrayFilefromId(id);
      return File(fileData,"application/pdf","somefile.pdf");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an ASP.NET MVC3 app I have a model that represents a user address
I have an MVC3/EF4.1 app that I'm building which now works fine on my
I have an ASP.NET MVC3 app and when the user clicks on my anchor
I have a requirement to implement user privilege elevation in an MVC3 web app,
I have mvc3 web app. inside that I have one Enquiry form once I
I have a vb.net MVC3 Razor app that generates PDF files. The problem is
I have an MVC3 app that uses a Telerik grid. I have a variable
I have an MVC3 app that has a details page. As part of that
I have an ASP.NET MVC3 app that features a form with a nested-table input
I have a few models in my MVC3 web app that have fields that

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.