Home > not working > response.binarywrite pdf error

Response.binarywrite Pdf Error

here for a quick overview of the site Help Center Detailed answers response.binarywrite not working to any questions you might have Meta Discuss the workings asp.net response binarywrite and policies of this site About Us Learn more about Stack Overflow the company Business

Response Binarywrite Pdf Not Working

Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack

Response.binarywrite Image

Overflow Community Stack Overflow is a community of 6.3 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Trying to stream a PDF file with asp.net is producing a “damaged file” up vote 5 down vote favorite 2 In one of my asp.net stream pdf to browser asp.net web applications I need to hide the location of a pdf file being served to the users. Thus, I am writing a method that retrieves its binary content from its location on a CMS system and then flushes a byte array to the web user. I'm getting, unfortunately, an error when downloading the stream: "Could not open the file because it is damadged" (or something similar to that, when opening the file in adobe reader). Question 1: what am I doing wrong? Question 2: can I download large files using this approach? private void StreamFile(IItem documentItem) { //CMS vendor specific API BinaryContent itemBinaryContent = documentItem.getBinaryContent(); //Plain old .NET Stream fileStream = itemBinaryContent.getContentStream(); var len = itemBinaryContent.getContentLength(); SendStream(fileStream, len, itemBinaryContent.getContentType()); } private void SendStream(Stream stream, int contentLen, string contentType) { Response.ClearContent(); Response.ContentType = contentType; Response.AppendHeader("content-Disposition", string.Format("inline;filename=file.pdf")); Response.AppendHeader("content-length", contentLen.ToString()); var bytes = new byte[contentLen]; stream.Read(bytes, 0, contentLen); stream.Close(); Response.BinaryWrite(bytes); Response.Flush();

ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Web Forms/Problem Streaming PDF File to IE Browsers Problem Streaming PDF File to IE Browsers [Answered]RSS 16 replies Last post Mar 05, 2013 08:06 AM by asuranceturix ‹ Previous Thread|Next

Content Disposition Inline Filename Pdf

Thread › Print Share Twitter Facebook Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support binarywrite c# Options Advanced Search Related Links GuidanceSamplesVideos Reply kevnworking None 0 Points 4 Posts Problem Streaming PDF File to IE Browsers Oct 18, content-disposition inline not working in ie 2006 10:29 PM|kevnworking|LINK All, I hope someone can help me here. Here is my problem. I put an ASP.NET (C#) application in place a few weeks ago. Everything is humming along great but then I get http://stackoverflow.com/questions/1300729/trying-to-stream-a-pdf-file-with-asp-net-is-producing-a-damaged-file a call from the owner of the site telling me that the PDF files are no longer displaying. I check this and sure enough, when you click on the link that displays the PDF file, the browser seems to lock up or just go blank. What's weird is, we discovered that if you hit the refresh button on the browser the PDF file will load into the browser just as it always http://forums.asp.net/t/1036628.aspx?Problem+Streaming+PDF+File+to+IE+Browsers did. Another frustrating thing - Firefox does not have this problem. It displays the file just fine. I have rebooted the server, restarted IIS, recycled the application pool, waved dead chicken bones over the computer - all to no avail. I stream the PDF files to the browser because they contain private information and they are not located within the web site itself. The application opens the PDFfile and then streams it to the browser. Here is the code that I use: Response.Buffer = true; Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "CIC Report"); FileStream fs; BinaryReader br; fs = new FileStream(documentPath, FileMode.Open); br = new BinaryReader(fs); Byte[] dataBytes = br.ReadBytes((int)(fs.Length - 1)); Response.BinaryWrite(dataBytes); br.Close(); fs.Close(); I have been racking my brain on this for about five or six hours and cannot find a solution. I have double checked my code against what others are doing and it appears the same. I have even tried a different method of streaming the data down with the same results. What kills me the most is this worked for two weeks without any problem and then suddenly just stops. I have tried it from multiple machines, all with the same results. Thanks for any help you can offer, Kevin Firefox ASP.NET 1.x IE ASP.NET c# PDF Reply mbanavige

24, 200642 Share 0 0 In this pick, I am sharing a project using which you can send PDF files to the https://blogs.msdn.microsoft.com/rahulso/2006/03/24/4-ways-to-send-a-pdf-file-to-the-ie-client-in-asp-net-2-0/ IE Client in four different ways. You may download the project by clicking here. Create a new C# Website. Whilecreating the following pages ensure that you DON'T have "Place code in Seperate file" checkbox as checked. You need to create 4 pages called "Way1.aspx", "Way2.aspx", "Way3.aspx" and "PDFContainer.aspx"without a code behind. So the four different ways which I was talking not working about is as follows… 1) You hit a button on a page and the page refreshes itself with a PDF file in the same instance of the IE Browser. You are not prompted to Open/Save/Cancel by the IE Client at all. The code for this page is as follows Way1.aspx <%@ Page Language="C#" %> Way 1

This page will refresh itself with a PDF file opened in the same instance of IE itself. Users will not get prompted to Save/Open/Cancel the PDF file. 2) You hit a button on a page and the pagethrows a Dialogboxsaying Open/Save/Cancel. You click on Save and the FileName is populated is the document is according to your taste (meaning you have to supply it explicitly). 3) Verify similar to 2 above, but the filename in the Dialogbox is the name of the Page (meaning, if you don't the supply name, the Dialogbox takes the name of the aspx file as the PDF file name). The code for this page is as follows… Way2.aspx <%@ Page Language="C#" %>