System Information

Impossible Is Nothing...

导航

File Uploading to Access Database using ASP.NET

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:

  1. File uploading to server hard disk.
  2. Uploading files ( binary data ) to the database.
  3. Displaying files ( binary data ) from the database.

File Uploading Using ASP.NET
Here are few Stardeveloper articles on this topic:

  1. File uploading to server hard disk.
  2. File uploading to Microsoft Access database ( this article ).
  3. Uploading images, determining size, width & height and resizing image files.

Problem
Let's first consider what we want to do. We want to:

  1. Upload one or more files to Microsoft Access database.
  2. 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.
  3. 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.
  4. View all the uploaded files.
  5. Allow the user to view the file online.
  6. Allow the user to be forced to download file. We'll see how this is done.
  7. Delete uploaded files.
  8. Set maximum file upload size limit.

Design
Our design comprises of following files:

  • Microsoft Access database:
    1. Files.mdb ( a data store for all the uploaded files )
  • Class file:
    1. GenericPage.cs ( base class for all of our code-behind classes )
  • 3 ASP.NET pages:
    1. default.aspx ( list all files )
    2. upload.aspx ( upload one or more files )
    3. file.aspx ( view, delete or download a file from database )
  • Optional files:
    1. build.bat ( a batch files to generate an assembly )
    2. 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.

  ( 13 Remaining ) Next


原文地址:http://www.stardeveloper.com/articles/display.html?article=2003031201&page=1

posted on 2005-06-13 11:04  SysInfo  阅读(355)  评论(0编辑  收藏  举报