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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:42:07+00:00 2026-06-18T07:42:07+00:00

I am using iTextSharp for creating pdf reports (files) and storing those on the

  • 0

I am using iTextSharp for creating pdf reports (files) and storing those on the web server where my application resides. I am able to create the file, go into the storage folder and open the file without a problem. Notice: The user is not to get the file automatically
downloaded on creation.

I want to give the user the option to download “old” reports from the server with a button.
This is working fine in IE (10) but not in Chrome and Firefox. I always get the error message:
There was an error opening this document. The file is damaged and could not be repaired.

I have this image button and on click I send the user to a Generic Handler (since my page contains Update Panels) according to this post (only using it partially for now).

This is the code that actually downloads the file:

 public void ProcessRequest(HttpContext context)
    {
        var _fileName = context.Request.QueryString["fileName"];

        using (var _output = new MemoryStream())
        {
            //var _fileSeverPath = context.Server.MapPath(_fileName);
            context.Response.Clear();
            context.Response.ContentType = "application/pdf";// "application/pdf";
            //context.Response.AppendHeader("Content-Length", _fileName.Length.ToString());
            context.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=" + Path.GetFileName(_fileName)));

            context.Response.WriteFile(_fileName);
            context.Response.Flush();
            context.Response.Close();
            context.Response.End();
        }
    }

As I said, this works fine in IE but not in Chrome and Firefox.
When I open the file in Notepad it seams that I only get about 1/3 of the file when downloaded in Chrome and Firefox.

Any suggestions would be greatly appreciated. Been trying to resolve this for a few days now..

  • 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-18T07:42:08+00:00Added an answer on June 18, 2026 at 7:42 am

    Ok, FINALLY.. I found the solution and it makes me feel like a fool at the same time..
    Removed context.Response.Close(); …then everything worked perfectly 🙂

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

Sidebar

Related Questions

I'm currently converting some legacy code to create PDF files using iTextSharp. We're creating
I m creating a pdf file on the server using iTextSharp. It is working
I'm using iTextsharp library to create PDF files. I can declare for A4 Landscape
How do one create PDF in memorystream instead of physical file using itextsharp. The
I am using iTextSharp for creating PDF for reports & send as attachment(). Pdf
Language : ASP.NET/VB.NET I am creating pdf file using itextsharp library. On my development
I'm creating a PDF file on the fly using ITextSharp and ASP.NET 1.1. My
I create a PDF file using itextsharp. It's created successfully and open with adobe
I’m generating PDF files from my C# 4.0 windows application using iTextSharp API. I’ll
i am using itextsharp and creating a PDF with images. currently the images i

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.