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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:43:04+00:00 2026-05-24T19:43:04+00:00

I spent some time this morning trying to help a colleague with an odd

  • 0

I spent some time this morning trying to help a colleague with an odd bug that currently has three of us stumped. The scenario is that we have a system under development which allows users to attach pdf files to a data record. The system uses a service to store and retrieve the files from a server and stores an identifier in an attachments table to indicate which files belong to which records.

Then, on two different pages within the app, we have a grid which displays the list of attachments for a record. Within the grid are link buttons which allow a user to open a given attachment. The link button raises a command event passing the identifier of the attachment as its argument. In the command event handler we grab the identifier from the argument, use it to retrieve the attachment from the service in the form of a byte array, and then override the response object to return the attachment. Here is the code:

byte[] byteFile = DataHandler.GetAttachmentDocument(selectedAttachmentID);
if (DataHandler.sErrorMsg != "")
{//Error trying to retrieve file...
    this.DisplayMessageBox(DataHandler.sErrorMsg);
}
else
{//File retrieved...
    Response.Clear();
    Response.Buffer = true;

    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=" + lblAttachmentName.Text);

    Response.Charset = "";
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    Response.BinaryWrite(byteFile);
    Response.Flush();
    Response.Close();
    Response.End();
}

Now this exact same code works perfectly on one page and fails on the other. In both cases when a button is clicked and a download dialog displays, click the open button and an adobe reader window opens. On the working page the reader window displays the requested document, but on the other page we get an error from the reader window stating: There was an error opening this document. This file cannot be found. Running in the debugger we can step through and see that we are getting the same number of bytes in byteFile, and that we are stepping through the full method without errors.

We have googled quite a bit on this and tried several variation to this code without having any luck. A couple of things I know we tried were changing the content type to an octet stream, adding the content length to the header, changing the buffer to false, removing the content disposition attribute. The only one that made a noticeable difference was removing the content disposition attribute, in that case the document displayed but it showed up in the original window, not a separate adobe reader window. One other idea which was proposed but not tried so far, would be to extract the grid and associated logic out to a web control which could then be reused on both pages. Any other suggestions?

  • 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-05-24T19:43:04+00:00Added an answer on May 24, 2026 at 7:43 pm

    While we never were able to work out exactly what was causing the problem, we did determine that it was at least somewhat user/machine specific. So our best guess is some sort of odd conflict, or caching issue, on the client side.

    What we ended up doing as a work around was developing a blank page which accepts the attachment ID and name on the query string, performs some security checks, and then returns the requested attachment. This gave us a single, reusable, module containing our attachment retrieval code.

    We then went into the pages that serve up the attachments and changed our grid templates from link buttons with command arguments to hyper links with a navigate URL bound to the path of the new page + query string arguments and a target of _blank.

    The end result is that we eliminated the errors without major changes to the page structure, maintained the desired end user experience, and have a code structure that is going to be easier to maintain.

    Thanks to Leon for the tip. While it did not fix the problem, it did help us clean up our code a bit.

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

Sidebar

Related Questions

I spent some time trying to figure out why this query isn't pulling the
Been struggling with this for quite some time so any help is appreciated. Spent
This has probably been answered before, but I have spent some time looking and
I've spent some time on Google and SO trying to figure this out and
I had to spent some time in finding and fixing a bug that I
yesterday I spent some time trying to find a bug. Long story short, finally
I spent some time trying to research a definitive answer for this and couldn't
I spent some time trying to get working this SELECT with CASE but I
My Friends, I spent quite some time on this one... but cannot yet figure
I recently spent some time trying to write some numbers as bytes to pipe

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.