Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-27
2
Medium Priority
?
273 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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