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

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

LVL 16
hankknightAsked:
Who is Participating?
 
Robert SchuttConnect With a Mentor Software EngineerCommented:
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
 
Robert SchuttSoftware EngineerCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.