File Uploading to Access Database using ASP.NET by Faisal Khan.
Overview
In this article we will learn how to upload one or more files from the client browser to
a Microsoft Access database using plain ASP.NET. We will not be creating or making use of any
commercial or home-made components, instead we will learn to make use of standard ASP.NET
HTML controls which are part of ASP.NET 1.0.
Uploading files to Microsoft Access is very useful and we'll learn in this article how
to do that.
File Uploading Using Plain ASP
If you are looking to upload files using plain ASP ( VBScript ) then here are few links
to popular Stardeveloper articles on how to do it:
- File uploading
to server hard disk.
- Uploading files
( binary data ) to the database.
- Displaying
files ( binary data ) from the database.
File Uploading Using ASP.NET
Here are few Stardeveloper articles on this topic:
- File uploading
to server hard disk.
- File uploading to Microsoft Access database ( this article ).
- Uploading images, determining size, width & height and resizing image files.
Problem
Let's first consider what we want to do. We want to:
- Upload one or more files to Microsoft Access database.
- Allow the user to select the files and leave the file input boxes empty if he/she doesn't
want to upload. We should handle this situation gracefully.
- Also provide other form options like input boxes for first and last names, favorite
programming languages etc so that we learn how to receive regular form post data along with
binary file data at the same time.
- View all the uploaded files.
- Allow the user to view the file online.
- Allow the user to be forced to download file. We'll see how this is done.
- Delete uploaded files.
- Set maximum file upload size limit.
Design
Our design comprises of following files:
- Microsoft Access database:
- Files.mdb ( a data store for all the uploaded files )
- Class file:
- GenericPage.cs ( base class for all of our code-behind classes )
- 3 ASP.NET pages:
- default.aspx ( list all files )
- upload.aspx ( upload one or more files )
- file.aspx ( view, delete or download a file from database )
- Optional files:
- build.bat ( a batch files to generate an assembly )
- Web.config ( to allow or restrict uploading of large files )
Solution
Let's code and build the solution.
i. Files.mdb
First of all we need to create a Microsoft Access database which can later be used to
store uploaded files. You can use this Access database on your ASP.NET web site without
worrying to pay additional licensing fees to your host. Making use of your Access database
is offered free of cost by all the ASP.NET hosts.
You'll be needing Microsoft Access 2000 installed on your system in order to create this
database. Just in case if you don't have Access 2000 ( or 2002 ) then don't worry, you can
download the zip file at the end of this tutorial which contains a pre-built Access 2000
database. You can then use that Access 2000 database on your system or upload it to your
server hard disk as you like.
Tip: No need to buy Microsoft Access 2000 ( or 2002 ) to make use of this tutorial.
|