Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - displaying PDF files from the DB
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

displaying PDF files from the DB

 Post Reply Post Reply
Author
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post Topic: displaying PDF files from the DB
    Posted: 02 January 2006 at 12:00pm
Hi all,

I have a problem with Files stored in SQL Server.

The PDF files are stored in the database in an Image field. I can get the file out of the database but when it opens Adobe Reader it gives an error saying the File is corrupt and cannot be fixed.

I have Word documents in the same table and I can download them then show them. I can also display Images from the DB, but not the PDFs.

Can anyone please help me??

Thanks
Lee


Back to Top
Leeb65 View Drop Down
Groupie
Groupie


Joined: 05 December 2003
Location: Germany
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote Leeb65 Quote  Post ReplyReply Direct Link To This Post Posted: 02 January 2006 at 12:20pm
Okay, I found out how to do it:
 
To download:

Response.ContentType = dsPDF.Tables[0].Rows[0]["strPDFFileWordMime"].ToString();

Response.OutputStream.Write( (byte[])dsPDF.Tables[0].Rows[0]["imgPDFFileWordDoc"], 0, Convert.ToInt32(dsPDF.Tables[0].Rows[0]["intPDFFileWordLength"]));

Response.AddHeader("Content-Disposition", "attachment;filename=" + dsPDF.Tables[0].Rows[0]["strPDFFileWordName"].ToString());

Response.Flush();

Response.End();

 
and to Display:

Response.ContentType = dsPDF.Tables[0].Rows[0]["strPDFFileWordMime"].ToString();

Response.OutputStream.Write( (byte[])dsPDF.Tables[0].Rows[0]["imgPDFFileWordDoc"], 0, Convert.ToInt32(dsPDF.Tables[0].Rows[0]["intPDFFileWordLength"]));

Response.AddHeader("Content-Disposition", "inline;filename=" + dsPDF.Tables[0].Rows[0]["strPDFFileWordName"].ToString());

Response.Flush();

Response.End();

 
it's the word inline in the header that makes it work.
 
 
Lee


Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.