Forced Download of PDF

D

Darren

Dear Groups,

I am attempting to allow the end user to save or open a pdf document
from the server. However, when the file is downloaded it is not a
pdf, but rather nonsensical garbage. Also, if attempting to save the
file, it only gives the option of file type "text document".

I've run the app on other machines and am fresh out of ideas.

Thanks in advance,

Darren

Code as follows:

Session["FilePath"]=Server.MapPath("../docPDF/") +
e.CommandName.ToString();

Response.ContentType="application/pdf";

Response.AddHeader( "content-disposition","attachment; filename=" +
Session["FilePath"].ToString());

FileStream sourceFile = new
FileStream(@Session["FilePath"].ToString(), FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();

Response.BinaryWrite(getContent);
 
G

Guest

Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/pdf";
try
{
Response.WriteFile( MapPath( "Sample.pdf") );
Response.Flush();
Response.Close();
}
catch
{
Response.ClearContent();
}
 
D

Darren

Hi Steve,

Thanks so much for your most prompt reply.

When I added the Response.Clear() and Response.End(), the following
resulted:

1) Registers as type Adobe Acrobat Control for Active X
2) Allows me to save, but the default document name is "Default", and
file type is Adobe Acrobat Document
3) When the user chooses to open rather than save, it ignores the
request and shows the save dialogue box.

Any ideas?

Thanks again,

Darren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top