Link to home
Start Free TrialLog in
Avatar of BritishJeff
BritishJeffFlag for United States of America

asked on

Saving a PDF file in SQL Server (2005) or using the FileSystem and a path in db (VB 2005)

OK, i have read various different opinion on whether a file should be inserted into a database, or whether it should be accessed through the filesystem.  I really havent made up my mind which way to go on this, but i can already think of a few problems with both.  I hope someone can help.

If you store the PDF inside a SQL database (lets say using an Image type), when you want to retrieve do you view it?  Ordinarily, with a file i would view with either the webbrowser control or the adobe reader activeX control, but both need a filename/source and dont seem to be able to view from a memorystream or byte array.

If i store the file using the filesystem on the server, and store the path in the does a local user retrieve the file when they are working offsite, remotely?  They can access the file using the path to the server when they are connected on the LAN, but when they are not, and just accessing the SQL server through the interner, how do they get access to the files then?

I would really like to know the best way to proceed as both ways seem problematic, yet i do need a solution.

Thanks so much,

Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

>> but when they are not, and just accessing the SQL server through the interner, how do they get access to the files then?

In that case you'll need to put them in a database, or create a shared folder on the webserver where the necessary files are stored (but if there are a lot of files, you won't have enough space probably)

HOW TO: Read and Write BLOB Data by Using ADO.NET Through ASP.NET

Read / Write BLOBs from / to SQL Server using C# .NET DataReader
Avatar of BritishJeff


Thanks, so it looks like my best option then is to put it into my SQL db, but i still have the issue of how to view the retrieved pdf.  I dont have a problem saving or retrieving the data (as your links illustrate), my issue is how to display the retrieved PDF file without writing it to a file, and then opening the file.  Is there a way to view the PDF without doing this.  I cant see any options in the webbrowser control or adobe reader control to view from a stream.  I dotn really want to buy a new control, so what are my options?  The wbebrowser has documentstream, but i dont think that works as i cant set the document type to application/pdf (it is a read only proeprty).
When you have a PDF in the databse it is much more easily accessible to a remote user, and it can be accessed in a more versatile manner (win app and web app).

To open it in a win app, pull the byte stream from the database to a temporary file, then open it with a system registered app (like Adobe Reader for PDF). When doing this from the webb app, you can use a memory stream and direct the output righ tto the ResponseBuffer. Previously set the Response to the appropriate mime type for PDF, and your browser will automatically prompt to Open or Save the PDF.
Thank you, but again that doesnt answer my question.  I asked whether the PDF file can be opened as a memory stream.  I already know how to write it as a file, but i would rather not have to write it as a local file, open it, and then delete it afterwards...far cleaner to be able ot open in a Windows App as a memroystream directly from the SQL server.
Avatar of lucius_the
Flag of Croatia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial