473,508 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Urgent!, download attachment corruption.

Hi,

When i download PDF document from asp.net page, it downloads but does not
open. Message shown is "file is damaged". The file opens when opened directly
from the folder.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim myFileInfo As New FileInfo(Session("dnload").ToString)
Dim myFilePath As String =
System.Configuration.ConfigurationManager.AppSetti ngs("UploadFolder").ToString & "\" & myFileInfo.Name
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Response.ContentType = "application/pdf"
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment;filename=" & myFileInfo.Name)
Response.WriteFile(myFilePath)
Response.Flush()
Response.End()

End Sub

What could be reason?
any thoughts are welcome.


Aug 8 '06 #1
4 1266
Have you examined the actual PDF file to see what's in it? I have seen where
the markup from a Page (the aspx portion) gets included in a file download.
Try setting it up so your ASPX page has ONLY the Page directive and NO OTHER
MARKUP.
Best of luck,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ibrahim." wrote:
Hi,

When i download PDF document from asp.net page, it downloads but does not
open. Message shown is "file is damaged". The file opens when opened directly
from the folder.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim myFileInfo As New FileInfo(Session("dnload").ToString)
Dim myFilePath As String =
System.Configuration.ConfigurationManager.AppSetti ngs("UploadFolder").ToString & "\" & myFileInfo.Name
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Response.ContentType = "application/pdf"
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment;filename=" & myFileInfo.Name)
Response.WriteFile(myFilePath)
Response.Flush()
Response.End()

End Sub

What could be reason?
any thoughts are welcome.

Aug 8 '06 #2
You need to pass the ContentLength header as well for the pdf to work.

Ibrahim. wrote:
Hi,

When i download PDF document from asp.net page, it downloads but does not
open. Message shown is "file is damaged". The file opens when opened directly
from the folder.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim myFileInfo As New FileInfo(Session("dnload").ToString)
Dim myFilePath As String =
System.Configuration.ConfigurationManager.AppSetti ngs("UploadFolder").ToString & "\" & myFileInfo.Name
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Response.ContentType = "application/pdf"
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment;filename=" & myFileInfo.Name)
Response.WriteFile(myFilePath)
Response.Flush()
Response.End()

End Sub

What could be reason?
any thoughts are welcome.
Aug 8 '06 #3

Hi Peter,

You are right, I examined the PDF contents & could see HTML embedded at end
of the file.

I tried removing everthing except page directive, but still the problem
exists?

Kindly give concrete solution;

thanks
"Peter Bromberg [C# MVP]" wrote:
Have you examined the actual PDF file to see what's in it? I have seen where
the markup from a Page (the aspx portion) gets included in a file download.
Try setting it up so your ASPX page has ONLY the Page directive and NO OTHER
MARKUP.
Best of luck,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ibrahim." wrote:
Hi,

When i download PDF document from asp.net page, it downloads but does not
open. Message shown is "file is damaged". The file opens when opened directly
from the folder.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim myFileInfo As New FileInfo(Session("dnload").ToString)
Dim myFilePath As String =
System.Configuration.ConfigurationManager.AppSetti ngs("UploadFolder").ToString & "\" & myFileInfo.Name
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Response.ContentType = "application/pdf"
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment;filename=" & myFileInfo.Name)
Response.WriteFile(myFilePath)
Response.Flush()
Response.End()

End Sub

What could be reason?
any thoughts are welcome.


Aug 9 '06 #4

Hi Peter,

You are correct, I examined the PDF file & could see HTML embedded at end of
the file.

I tried your suggestions but it does not work.

any concreate solutions?

Thanks
"Peter Bromberg [C# MVP]" wrote:
Have you examined the actual PDF file to see what's in it? I have seen where
the markup from a Page (the aspx portion) gets included in a file download.
Try setting it up so your ASPX page has ONLY the Page directive and NO OTHER
MARKUP.
Best of luck,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ibrahim." wrote:
Hi,

When i download PDF document from asp.net page, it downloads but does not
open. Message shown is "file is damaged". The file opens when opened directly
from the folder.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Dim myFileInfo As New FileInfo(Session("dnload").ToString)
Dim myFilePath As String =
System.Configuration.ConfigurationManager.AppSetti ngs("UploadFolder").ToString & "\" & myFileInfo.Name
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Response.ContentType = "application/pdf"
HttpContext.Current.Response.AppendHeader("content-disposition",
"attachment;filename=" & myFileInfo.Name)
Response.WriteFile(myFilePath)
Response.Flush()
Response.End()

End Sub

What could be reason?
any thoughts are welcome.


Aug 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2254
by: GRE | last post by:
I'm hoping someone can help with this problem; I've seen only a handful of postings related to it, but with no clear resolution. I have an ASP.NET 1.1 page that downloads requested files via the...
0
844
by: Craig Fox | last post by:
Does anyone know of a fix for this. I have found several references to it but this one describes it the best: http://www.systemwebmail.com/faq/4.4.8.aspx Unfortunately no solution is aparent...
0
1148
by: Stu | last post by:
Hi, I have a 3 tier system using web services I want to attach on the 3rd tier - data access to the middle tier - business rules and call the business rule tier from the front end to get the...
0
1029
by: Ibrahim. | last post by:
Hi, When I open the download attachment link from my asp.net 2.0 application, I get to see filedown download dialog box. When I select 'save' the file name saves correctly. The file name is...
5
2300
by: djhexx | last post by:
Hello. I have an ASP.NET application (C#) that I allow users to upload files. Files get stored in a SQL2005 database. The file data is stored in a varbinary(max) column. When the user uploads...
2
1135
by: faiz03l | last post by:
My program can catch the attachment of email but I don't know how to save the attachment(download attachment) ? Can use the CommonDialog? or other? I need solution... Thank's
2
1264
by: manirajmurali | last post by:
hi all, i have face this problem more 3 days.. if anybody help me.. i have upload file through php coding .. i have download that same file from server.. its coming empty file.. i dont know...
2
1839
by: sbettadpur | last post by:
hello, Let me explain my requirement 1) I need to download attachment which are there in Microsoft Outlook email client. 2) Then i have to parse those files. thanks
1
47351
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7123
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5627
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.