tags:

views:

133

answers:

5

I have been playing around with creation of pdf documents for a project that I'm working on. I would like to store the generated pdf document in a SQL database and then later be able to retrieve this pdf as well.

What are some suggestions for doing this? Can the document be stored in the database without physically creating the document on the server?

+1  A: 

What are some suggestions for doing this? Can the document be stored in the database without physically creating the document on the server?

Sure just create the pdf as a byte stream (byte[]) and store it in the database. Depending on what you use to create it, you don't have to write it to the file system.

Actually, on the argument about where to store it. If you have SQL server 2008, you want to use that. It will store the file on the file system, but you can access it through the database like you would with any other data. You get the best of both worlds.

Kevin
A: 

Save the PDF as a byte[] then you can use itextsharp to created the PDF when ready for viewing.

gmcalab
+1  A: 

This is again going to bring up the debate for/against storing things on the file system or within sql server itself.

It really depends on your needs, the size that you're expected, etc. Here are some references, each with more references.

http://stackoverflow.com/questions/8952/storing-a-file-in-a-database-as-opposed-to-the-file-system

http://stackoverflow.com/questions/766048/store-image-in-database-or-in-a-system-file-closed

Aaron
+1  A: 

Keep in mind that SQL Server 2008 now has the FILESTREAM data type. You can write the data to the file system, yet still store it in a column.

John Saunders
I like this approach.
mwright
A: 

You can use a table like this to store files in SQL Server.

CREATE TABLE [Documents]
(
    [FileName] nvarchar(1000),
    [FileContent] varbinary(max)
)
Anthony Faull