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 7861275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:38:53+00:00 2026-06-02T22:38:53+00:00

I have a web application allowing to download files from the server. Documents might

  • 0

I have a web application allowing to download files from the server. Documents might be Office files (.docx, pptx, .xslx) or Pdf.

The logic is quite simple: on click from client side a web service is called and calls an aspx page (Print.aspx) passing the needed parameters. Print page calls a web service to retrieve the selected documents binaries and write them in the response:

protected void Page_Load(object sender, EventArgs e)
    {
        string fileName = Request.QueryString["fname"];
        if (string.IsNullOrEmpty(documentID) == false)
        {
            byte[] document = GetPhysicalFile(documentID); //Get the binaries
            showDownloadedDoc(document, fileName);
        }
    }

private void showDownloadedDoc(byte[] document, string fileName)
{
Response.Clear();
Response.ContentType = contentType;

Response.AppendHeader("content-disposition", string.Format("attachment; filename=\"{0}\"", fileName));
Response.BufferOutput = false;
Response.BinaryWrite(document);
Response.Close();

 }

Pdf documents are opened in the Print.aspx page and the aspx page is loaded only once. For Office files, the Page_Load() method is invoked 3 times.

After the first time the dialog for Open/Save the document is opened and if “Open” ic clicked, then the Page_Load is called twice and after that the document is finally oepend in MS Word, for instance.

Is there a way I can prevent to have multiple page loads for opening these documents? I would like to avoid having to save the file on Server Side and Redirect to that URL, since a file for each access would be created.

  • 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-02T22:38:55+00:00Added an answer on June 2, 2026 at 10:38 pm

    Here is an example with a GenericHandler

    public void ProcessRequest(HttpContext context)
    {
    
      string filePath; // get from somewhere
      string contentType; // get from somewhere
    
      FileInfo fileInfo = new FileInfo(filePath);
    
      context.Response.Clear();
      context.Response.ContentType = contentType;
      context.Response.AddHeader("content-disposition", "attachment; filename=" + Path.GetFilename(filePath));
      context.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
      context.Response.TransmitFile(filePath);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application that functions as a dashboard, allowing a user to
I have web application of which major part is javascript. I request images from
I have a web application and two class files, First class is MyClass.class which
I have a web application which displays pdf's in an IFrame. I recently made
In a web application I have an upload folder where all users' files are
I have web application deployed on websphere application server 7.0. User logins using /j_security_check.
I have web application written in java using Eclipse. It has just one servlet
I have web application which we deployed in a production . We have separate
I have web application and I do not really care about IE6 users. However
I have web application Project having RPC call. one RPC async is working fine.

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.