views:

2916

answers:

8

I am trying to upload files (.doc/.pdf) to a SQL database (2005) but I am really struggling to find any step by step guides.

This is what happens on my ASP form:

  • User selects a document
  • Document is currently upload to a temp file and sent to a email address

However it also needs to be stored within a database field.

I have set the field type within the database to Image. But I am unsure about how I save the binary data information when all I really have is a link to the document (for example C://) from the user.

I also want to be able to download this document at a later date, this is also possible?

Thank you in advance for any help.

Thanks Clare

+1  A: 

(Storing binary data in a database is usually a bad idea.)

Classic ASP doesn't have built-in support for file upload, so you need a upload compontent on the server. For most parts, there are samples included with the upload component that shows how to upload directly into a database.

svinto
+1  A: 

You can't do this natively with classic ASP yourself, but you can buy ASPUpload to do it for you for $200. If you check their web site, it looks like it hasn't been updated in quite a while, but that's because neither has classic ASP, heh.

I used this myself back in 2001-2005 to upload images, documents, and the like with classic ASP. It's easy to use, easy to get started with, and works great. Two thumbs up.

Brent Ozar
A: 

I have successfully used FreeASPUpload for your first requirement.
I think the upload to SQL will be fairly simple once you find the right answer. I don't have that piece of the puzzle myself, regrettably.

WakeUpScreaming
A: 

I quitted using ASP about seven years ago, but I remebered I had some pure ASP code to accomplish this back then. The code I've linked to is exactly how I used it in my project in 2001. The class itself wasn't written by me, but was found on the net somewhere (seems it shipped with something called Sagasnet webstudio). The example is mine, and not exactly something I'm proud of these days. Hope it helps.

Emil H
+2  A: 

As it was mentioned before -- storing binary data in database is usually not good idea.

Wouldn't be good enough to store file on disk, where documents table id/PK becomes file name and store just file name/id, original file name and file description in database?

This would solve most of your problems:

  • Store/generate links to documents in easy way.

  • Easy downloads (just link to file on disk).

This also prevent from problems with fast growing database size and writing and maintaining extra code to store, search for and serve documents stored in database.

If you really need just a link to document this is, in my opinion, better solution.

Here is VB6 code from Microsoft support site which saves uploaded file into file on web server.

Currently it does not do what you want (stores uploaded file on disk, not in database), but I hope it won't be hard to amend that.

Good luck!

Grzegorz Gierlik
+2  A: 

Definately, use freeaspupload to upload the file. It's pretty easy to use. Once you get the file uploaded you will need to binary read the file and then write that binary stream to your db. This website seems to have a working example of what you are trying to do. Look at the code and figure out what parts you need.

Fred Clown
A: 

Here is a link that shows you how to upload files to a database. I have it working, now I just need to figure out how to retrieve it.

link text

Scott and the Dev Team
+1  A: 

I've used this "Advanced ASP Uploader" from CodeProject before now. That'll help you get the file to the server. Then you just need to store the bytes in the database.

Whether that's a good idea or not I'll leave to others as there's been a bit of debate about that in this recent thread.

Chris J