Solved

ASP.NET/VB: Reading file causes it to become corrupt

Posted on 2014-01-27
2
263 Views
Last Modified: 2014-01-28
This causes good PDF documents to become corrupt.  I cannot view them after downloading them from this:
Dim pdfFileNew As System.IO.FileInfo
pdfFileNew = My.Computer.FileSystem.GetFileInfo(resultFile)
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=brochure.pdf")
Response.AddHeader("Content-Length", pdfFileNew.Length.ToString().Length)
Response.ContentType = "application/octet-stream"
Response.WriteFile(resultFile)
Response.End

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39814381
The expression
pdfFileNew.Length.ToString().Length

Open in new window

returns the length of the string that represents the length of the file. So that should be
pdfFileNew.Length.ToString()

Open in new window

0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39814384
PS: For good measure, I often see people adding a
Response.Flush()

Open in new window

before the .End() but that may be a remnant from the past and not really needed any more.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to make search between pages 17 59
JQuery on multiple lines 3 49
JQuery DataTable Functionality 8 55
Adding Clickable Links to JQuery Data Items 24 56
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question