Solved

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

Posted on 2014-01-27
2
248 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now