Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Force Download PDF Problem

Reply
Thread Tools

Force Download PDF Problem

 
 
gaubo79
Guest
Posts: n/a
 
      12-20-2005
I am wishing to force the Open|Save dialog box for a PDF and Excel
file.

I am using the following code:

Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" +
saveFilename );
Response.Flush();
Response.WriteFile(savePath);

While this works perfect for the Excel file, however, the PDF file does
not open, whether direct from the dialog box or by saving it to disk
and opening it, I get the following error in Adobe Acrobat Reader (v5.0
& v7.0):

"There was an error opening this document. The file is damaged and
could not be repaired."

The original PDF file is okay. Also, the size of the original PDF is
50k, where as the one that is downloaded to the client is 237k.

I have tried various other things such as creating a FileStream and
using Response.BinaryWrite, and various other ContentTypes, including
application/pdf.

Has anyone had this before, or know of a workaround? Ideally I would
like the dialog box to always appear for this pdf.

 
Reply With Quote
 
 
 
 
RCS
Guest
Posts: n/a
 
      12-20-2005
I know you're looking for something helpful - but I can say, that looks 100%
correct.. so if nothing else, it doesn't appear to be anything obvious. Good
luck

"gaubo79" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I am wishing to force the Open|Save dialog box for a PDF and Excel
> file.
>
> I am using the following code:
>
> Response.Clear();
> Response.ContentType = "application/octet-stream";
> Response.AddHeader("Content-Disposition", "attachment; filename=" +
> saveFilename );
> Response.Flush();
> Response.WriteFile(savePath);
>
> While this works perfect for the Excel file, however, the PDF file does
> not open, whether direct from the dialog box or by saving it to disk
> and opening it, I get the following error in Adobe Acrobat Reader (v5.0
> & v7.0):
>
> "There was an error opening this document. The file is damaged and
> could not be repaired."
>
> The original PDF file is okay. Also, the size of the original PDF is
> 50k, where as the one that is downloaded to the client is 237k.
>
> I have tried various other things such as creating a FileStream and
> using Response.BinaryWrite, and various other ContentTypes, including
> application/pdf.
>
> Has anyone had this before, or know of a workaround? Ideally I would
> like the dialog box to always appear for this pdf.
>



 
Reply With Quote
 
 
 
 
Edwin Knoppert
Guest
Posts: n/a
 
      12-20-2005
1) Use ClearHeaders() and ClearContents() CH is imo important for
authentication issues.
2) Response.End really seems to flush, Response.Flush seems not enough.
3) Not using Response.end seems to be a problem on localhost only so far.

I ran across the R.E issue yesterday,.
Odd, i was trying to avoid this end.



"RCS" <(E-Mail Removed)> schreef in bericht
news:AIWpf.4206$(E-Mail Removed) ...
>I know you're looking for something helpful - but I can say, that looks
>100% correct.. so if nothing else, it doesn't appear to be anything
>obvious. Good luck
>
> "gaubo79" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>>I am wishing to force the Open|Save dialog box for a PDF and Excel
>> file.
>>
>> I am using the following code:
>>
>> Response.Clear();
>> Response.ContentType = "application/octet-stream";
>> Response.AddHeader("Content-Disposition", "attachment; filename=" +
>> saveFilename );
>> Response.Flush();
>> Response.WriteFile(savePath);
>>
>> While this works perfect for the Excel file, however, the PDF file does
>> not open, whether direct from the dialog box or by saving it to disk
>> and opening it, I get the following error in Adobe Acrobat Reader (v5.0
>> & v7.0):
>>
>> "There was an error opening this document. The file is damaged and
>> could not be repaired."
>>
>> The original PDF file is okay. Also, the size of the original PDF is
>> 50k, where as the one that is downloaded to the client is 237k.
>>
>> I have tried various other things such as creating a FileStream and
>> using Response.BinaryWrite, and various other ContentTypes, including
>> application/pdf.
>>
>> Has anyone had this before, or know of a workaround? Ideally I would
>> like the dialog box to always appear for this pdf.
>>

>
>



 
Reply With Quote
 
Joey
Guest
Posts: n/a
 
      12-20-2005
If, by some chance, you have entered an IIS->asp.net mapping for PDF
documents, delete it. The problem will go away. This happened to me
when I tried to add a mapping so as to allow for asp.net to control
security on PDF documents.

gaubo79 wrote:
> I am wishing to force the Open|Save dialog box for a PDF and Excel
> file.
>
> I am using the following code:
>
> Response.Clear();
> Response.ContentType = "application/octet-stream";
> Response.AddHeader("Content-Disposition", "attachment; filename=" +
> saveFilename );
> Response.Flush();
> Response.WriteFile(savePath);
>
> While this works perfect for the Excel file, however, the PDF file does
> not open, whether direct from the dialog box or by saving it to disk
> and opening it, I get the following error in Adobe Acrobat Reader (v5.0
> & v7.0):
>
> "There was an error opening this document. The file is damaged and
> could not be repaired."
>
> The original PDF file is okay. Also, the size of the original PDF is
> 50k, where as the one that is downloaded to the client is 237k.
>
> I have tried various other things such as creating a FileStream and
> using Response.BinaryWrite, and various other ContentTypes, including
> application/pdf.
>
> Has anyone had this before, or know of a workaround? Ideally I would
> like the dialog box to always appear for this pdf.


 
Reply With Quote
 
gaubo79
Guest
Posts: n/a
 
      12-21-2005
Joey,

I certainly haven't entered one, is there anyway it could be there by
default?

I had a look through IIS manager, but couldn't find anything, where
would it be if it was in place?

Thanks

Joey wrote:

> If, by some chance, you have entered an IIS->asp.net mapping for PDF
> documents, delete it. The problem will go away. This happened to me
> when I tried to add a mapping so as to allow for asp.net to control
> security on PDF documents.
>
> gaubo79 wrote:
> > I am wishing to force the Open|Save dialog box for a PDF and Excel
> > file.
> >
> > I am using the following code:
> >
> > Response.Clear();
> > Response.ContentType = "application/octet-stream";
> > Response.AddHeader("Content-Disposition", "attachment; filename=" +
> > saveFilename );
> > Response.Flush();
> > Response.WriteFile(savePath);
> >
> > While this works perfect for the Excel file, however, the PDF file does
> > not open, whether direct from the dialog box or by saving it to disk
> > and opening it, I get the following error in Adobe Acrobat Reader (v5.0
> > & v7.0):
> >
> > "There was an error opening this document. The file is damaged and
> > could not be repaired."
> >
> > The original PDF file is okay. Also, the size of the original PDF is
> > 50k, where as the one that is downloaded to the client is 237k.
> >
> > I have tried various other things such as creating a FileStream and
> > using Response.BinaryWrite, and various other ContentTypes, including
> > application/pdf.
> >
> > Has anyone had this before, or know of a workaround? Ideally I would
> > like the dialog box to always appear for this pdf.


 
Reply With Quote
 
gaubo79
Guest
Posts: n/a
 
      12-21-2005
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType="application/octet-stream";
Response.AddHeader("content-disposition","attachment; filename=" +
saveFilename);
Response.WriteFile(savePath);
Response.End();

This works fine, many thanks.

 
Reply With Quote
 
giridhar86 giridhar86 is offline
Junior Member
Join Date: May 2011
Posts: 1
 
      05-19-2011
This works fine, many many many thanks so nice of you . [/QUOTE]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
Nike Air Force Ones,Air Force One Air Force One-1 lky52193@gmail.com Computer Support 0 01-17-2008 04:40 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:46 PM
Nike Air Force Ones,Air Force One Air Force One-1,25th anniversary lky52112@gmail.com Digital Photography 0 01-15-2008 04:34 PM
Javscript to force download of PDF NUG-IT HTML 11 07-26-2003 02:44 AM



Advertisments