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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:12:41+00:00 2026-06-12T03:12:41+00:00

I’m working on a ASP.NET (3.5) website that contains a treeview; the nodes’ values

  • 0

I’m working on a ASP.NET (3.5) website that contains a treeview; the nodes’ values are set to a filepath (on the server) of a PDF file. When the user clicks a treenode, the server-side code gets the node value (file path), creates a FileInfo object, and (after setting all the header Content-type, Cache-Control, etc. correctly) calls Response.TransmitFile(xxxxpath) to send to the user’s browser.

This works fine on the major browsers, on major devices (PCs, Macs, iOS devices). The file downloads correctly and opens on the user’s machine. But on certain devices and certain browsers, the PDF file does not open. On Android devices, it appears that Firefox downloads and opens the PDFs correctly, but the stock Android browser does not. On a Kindle Fire, it appears the Silk browser downloads the file successfully, but when trying to open it, I see an error: “PDF trailer not found”….or it says the PDF is DRM-protected (which it is not). I haven’t tried another browser (if there is one) on the Fire.

I’ve experimented using anchor links in static HTML markup, and the problem browsers appear to download and display the PDFs correctly when accessed this way. There seems to be an issue (inconsistency?) with the way ASP.NET sends the response to the browser when done via code. I’ve used Response.Flush, Response.WriteFile, Response.BinaryWrite, Response.Close, Response.End, etc., and they all produce the same result: MOST browsers handle the file, but SOME cannot handle the PDF.

So, is there some issue with the way ASP.NET constructs the Response object (especially when sending back PDFs) that some browsers don’t like? TIA.

  • 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-12T03:12:43+00:00Added an answer on June 12, 2026 at 3:12 am

    Quite simply, the answer to your question is “No.” You may want to post your code if you have doubts about whether or not you’re doing it correctly; otherwise: ‘no’. 🙂

    I would think the browsers you mentioned are much more suspect than something as simple and established as writing to the Response stream.

    For reference here is a tried and true way I do it using iHttpHandler:

        public void ProcessRequest(System.Web.HttpContext context)
        {
            string sFilePath = context.Server.MapPath(String.Concat("~/App_LocalResources", context.Request.QueryString["path"]));
            try
            {
                context.Response.Clear();
                context.Response.ContentType = "application/octet-stream";
    
                int iReadLength = 16384;
                int iLastReadLength = iReadLength;
                byte[] buffer = new byte[iReadLength];
                if (System.IO.File.Exists(sFilePath))
                {
                    System.IO.FileInfo fInfo = new System.IO.FileInfo(sFilePath);
                    context.Response.AddHeader("Content-Length", fInfo.Length.ToString());
                    context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"", fInfo.Name));
                    using (System.IO.FileStream input = new System.IO.FileStream(sFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        try
                        {
                            while (iLastReadLength > 0 && context.Response.IsClientConnected)
                            {
                                iLastReadLength = input.Read(buffer, 0, iLastReadLength);
    
                                if (iLastReadLength > 0)
                                {
                                    context.Response.OutputStream.Write(buffer, 0, iLastReadLength);
                                    context.Response.OutputStream.Flush();
                                }
                            }
                            context.Response.Flush();
                        }
                        catch
                        {
                        }
                        finally
                        {
                            input.Close();
                        }
                    }
                }
            }
            catch
            {
            }
            finally
            {
            }
        }
    

    Since you’ve indicated you are pulling the file from another place, here is how to write that to a memory stream. Just pull from your Response Stream from the remote server (or File Stream, Sql Binary Reader, w/e really), then reset your MemoryStream position and then use the functionality above to write to your Response stream to the client.

    int iReadLength = 16384;
    long lLastReadLength = iReadLength;
    long lDataIndex = 0;
    byte[] buffer = new byte[iReadLength];
    using (System.IO.MemoryStream msTemp = new System.IO.MemoryStream())
    {
        while (lLastReadLength > 0)
        {
            lLastReadLength = reader.GetBytes(0, lDataIndex, buffer, 0, iReadLength);
            lDataIndex += lLastReadLength;
    
            if (lLastReadLength > 0)
            {
                msTemp.Write(buffer, 0, Convert.ToInt32(lLastReadLength));
                msTemp.Flush();
            }
        }
    
        // Reset Memory Position
        msTemp.Position = 0;
    
        // Now write to the Response Stream here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.