Pure ASP File Upload

by Jacob Gilley

As a regular to ASP 101, I feel it neccesary to give a little back to the site that keeps me on top of things in the world of ASP. And so, I give you the FileUploader ASP Library. In a nutshell, the FilerUploader library is simply a single ASP include that provides an object-oriented approach to getting files from Internet clients.

I have seen numerous "pure ASP" upload solutions, some you even had to purchase, that did the job, but required you to wade through pages of code just to see how things worked. Then there are the COM components that you can buy that do what you want and more, but cost an arm and leg to obtain. What I wanted was something simple, centralized, easy to use and FREE! The FileUploader Library was the solution and now I want to share my work with fellow developers.


The library consists of two VBScript classes: FileUploader and UploadedFile. The FileUploader is the top-level object in the model and is the only one that you will need to instantiate.

Here is how to do it: (this assumes that you have included "upload.asp")

  Dim MyUploader
  Set MyUploader = New FileUploader


Now once your FileUploader object is initialized, you can begin recieving the uploaded data from the client by a single call to the Upload() method.


Or, since Upload() is the default method, you can use a shortcut and start the upload process like this: (Use one or the other, not both)


Once that is complete, you can begin access and saving the file to your hard-drive or to a database. The uploaded files are accessed through the Files Collection of the FileUploader object. The Files Collection is a set of UploadedFile objects that represent each file uploaded.

Here is an example of how to enumerate the Files Collection and write each uploaded files' information to the browser:

  Dim File
  For Each File In MyUploader.Files.Items
    Response.Write "File Name:" & File.FileName
    Response.Write "File Size:" & File.FileSize
    Response.Write "File Type:" & File.ContentType


Here is an example of how to access a specific file in the Files Collection using the HTML file input element name as the Index:

  Response.Write "File Name:" & MyUploader.Files("file1").FileName
  Response.Write "File Size:" & MyUploader.Files("file1").FileSize
  Response.Write "File Type:" & MyUploader.Files("file1").ContentType


For simplicity sake, I will be the using the For Each...Next variation for the following samples. Now, all the files are uploaded and its time to put them somewhere. There are two places you can save the uploaded files...on your hard-drive or to a database.

Here is how to save the files to disk:

  Dim File
  For Each File In MyUploader.Files.Items
    File.SaveToDisk "C:\UploadedFiles"


And how to save to a database: (Replace "MyUploadTable", "CONNECT STRING.." and field names accordingly)


  Dim RS
  Dim File

  Set RS = Server.CreateObject("ADODB.Recordset")
  RS.Open "MyUploadTable", "CONNECT STRING OR ADO.Connection", 2, 2

  For Each File In MyUploader.Files.Items

    RS("filename") = File.FileName
    RS("filesize") = File.FileSize
    RS("contenttype") = File.ContentType

    File.SaveToDatabase RS("filedata")



I think that should just about cover everything. I hope this helps out and that you found my blathering somewhat interesting. If you have any questions or comments about this article or the code provided, feel free to email me. (avis7@airmail.net)

You can download the library and sample files below (4 KB).

p34c3 +0 4|| c0d3rz!

Update: Pure ASP File Upload Gets a Speed Boost

Jacob Gilley's Pure ASP File Upload is an effective, free method for uploading user files to your server. Although well implemented, I found that the file I/O needed improvement. Concatenation is quite slow in VBScript and it was actually faster to write a single byte at a time to the disk than to concatenate the file prior to saving.

Here Robbert Nix's improved concatenation algorithm comes to the rescue. I stumbled upon this algorithm when searching for performance enhancements in VBScript. Essentially Nix's code allows Gilley's Pure ASP File Upload to return to concatenation as a viable method for preparing the file prior to saving.

Two files are included with this implementation: upload.asp and buffering.inc. These files are meant to be incorporated with the existing distribution for Gilley's Pure ASP File Upload. The upload.asp file replaces the existing version and the include file buffering.inc is used to improve upload time.

Note: if you replace your existing version of upload.asp you must also copy buffering.inc to the same directory! No changes in existing upload pages are required to take advantage of this upgrade.

Gilley's Pure ASP File Upload files are needed and can be found above.

You can download the updated upload.asp and new buffering.inc in a zip file, fileuploader_buffering.zip, below (3.4 KB)

Do Many Things ... Well

Update: Even Faster Yet...

It seems that the update above caught the atention of one of our other authors... here's his message:

Hello. I already have a few articles posted on your website so far. I just got your newsletter concerning ASP uploads: Update: Pure ASP File Upload Gets a Speed Boost

While this may be faster - it is still very slow. I have found a way around this in the past and had posted my findings on planet source code at:


I am including the upload_files_without_com_v2.zip file (below) (28 KB) for you to go over and review with this message. The zip file also includes a screen shot to demonstrate the simplicity of the code, and also contains a working sample. It is commented well and uses classes for a more object-oriented approach. Rather then converting each character between ansi and unicode 1 at a time - this class calls the ADODB Stream object to do it all at once. ADO 2.5+ is required along with vbScript 5.0+

I have had very good reviews posted by others about this code on planet source code.

Allowing files to be translated quicker allows users to post larger files before the server times out. Happy Coding!


Update: Listing the Files That Have Been Uploaded

Our "Pure ASP File Upload" article has been getting update after update recently and here's one more. When we left it last, updated files were getting entered into a database. This update brings a simple little script to display a list of those files. Here's the message:

I just wanted to share some code I came up with to display all the files uploaded to the database using Lewis Moten's code (which was very useful and fairly easy to use). I needed to create an area on our company website where the advertising and sales staff could share files back and forth easily but I found that Lewis's code only took care of the upload part. We needed to be able to view all the files as well.

Well, here it is. It just runs through the database until it reaches End Of File (EOF) and displays the filenames as links to that file. It requires Lewis Moten's DataFile.asp file to work but there is no need to modify it. The modifications have been made in my code to make it work with that file as is.

Dim oConn
Dim oRS
Dim sSQL
Dim lngFileID

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" _
	& Server.MapPath("db\Files.mdb"))

sSQL = "SELECT FileID, FileName, Date FROM Files " _
	& "ORDER BY Date desc, FileName"

Set oRS = oConn.Execute(sSQL)

If oRS.EOF Then
	Response.Write("<font face=arial size=2><b>There are " _
		& "currently no files in the database.</b></font><br>")
	Do While NOT oRS.EOF
		lngFileID = oRS("FileID").Value
		Response.Write("<a href=DataFile.asp?FileID=" _
			& lngFileID & " target=_blank>" _
			& oRS("FileName").Value & "</a><br>")
End If

Set oRS = Nothing
Set oConn = Nothing

The only thing that might throw people is that I've changed the path to the database since mine is stored in the "db" directory on my server therefore the path is db/Files.mdb. I've also included an ORDER BY clause in my sql statement to display the files from newest to oldest and then in alpha order by filename. This code can be placed anywhere on your page that you want the files displayed. You can also set it up to display the files in multiple columns across the page in a <table> instead of one long column down the page but you need to add additional "If NOT oRS.EOF Then" code before each new table cell. I've used this code on a page with other asp code so if you use it by itself you'd need to add the Option Explicit statement at the top.

Thanks for the great asp resource. Many of my peers have recommended your site to me when I've had questions about developing asp solutions for various things on my websites. Have a great day.

Bryan Hovey

Thanks Bryan... I'm sure you're not the only one who needs this functionality. A number of our users are sure to find this helpful.

About the Author

From ASP101

Articles originally posted on ASP101.com



  • Writing binary data out by the FileSystemObject stopped working recently

    Posted by Don Hughes on 03/22/2016 07:11am

    Recently our file upload code, based partially on techniques invented by Jacob Gilley stopped working. This was because some stricter validations now seem to be taking place. The code would create a 0 byte file but then fail to write to it - probably because a binary file produces bytes that aren't in the ASCII range. Attempting to fix this using an ADODB.Stream object led to the same problem for some strange reason. I then found Lewis Moten's code that gets around the problem in ADODB.Stream by type-casting the byte array through a Recordset object. I implemented something similar in our code and the problem was solved. The code you need is Private Function WashTheBytes(ByRef pbinBinaryData) Dim lobjRs Dim llngLength Dim lbinBuffer llngLength = LenB(pbinBinaryData) Set lobjRs = Server.CreateObject("ADODB.Recordset") Call lobjRs.Fields.Append("BinaryData", adLongVarBinary, llngLength) Call lobjRs.Open() Call lobjRs.AddNew() Call lobjRs.Fields("BinaryData").AppendChunk(pbinBinaryData) ' Update / Convert Binary Data to the Byte Subtype Array that the ADODB.Stream is expecting Call lobjRs.Update() ' Request binary data and save to stream lbinBuffer = lobjRs.Fields("BinaryData").GetChunk(llngLength) ' Close recordset Call lobjRs.Close() ' Release recordset from memory Set lobjRs = Nothing ' Return Bytes GetBytes = lbinBuffer End Function Then you can oStream.Write WashTheBytes(FileData) I hope this helps someone.

  • Using an interstitial page?

    Posted by James on 12/18/2015 05:38pm

    Suppose we need to select a file along with filling out a form, and need to insert an interstitial page for the user to review their entries, before executing the upload? How would we persist the file all the way to the upload code?

  • www-urlencoded

    Posted by Gaz on 10/21/2015 04:18pm

    Hi, Is there anyway to capture x-www-urlencoded data - I know its slower but is the only format available to me due to restrictions! Thanks,

  • Over write the existing file - SaveAs

    Posted by sivasai on 02/03/2015 06:17am

    Hi The file upload is working fine. But then when i am trying to edit and upload new file in the place of existing file how can handle this. Can you please help me on this?

  • Can only upload files below 200k

    Posted by Ian Mellors on 01/05/2015 01:38am

    Hi, I am using IIS7 and the code will not upload a file greater than 200k, any ideas?

    • Solution: Can only upload files below 200K

      Posted by Anthony Osika on 12/10/2015 11:39am

      Increase the "Maximum Requesting Entity Body Limit" parameter in the IIS ASP Limits Properties.

  • VP

    Posted by James on 02/09/2014 08:17am

    I have similar problem to view the upload the file with the fileuploader class. Before I upgraded host server from Windows 2003 to 2008, iis5 to iis7, I have no problem to source this script for uploading files and images. However, after migrating to Windows 2008 and iis7, I still can upload to designate directory with same file size but can't view the file or image at all. Do you have any insight for the fix? Thanks lots

  • Bug in clsField.cls

    Posted by Nick on 07/30/2013 11:18am

    Not all browsers pass the full file path in the content-disposition header, some pass the name only (Chrome for one). In that case the FileName property will be empty, as it depends on a "\" character to extract the file name from the path. Starting at line 198 in clsField.asp, change this: ' Parse File Name If Not InStrRev(pstrPath, "\") = 0 Then FileName = Mid(pstrPath, InStrRev(pstrPath, "\") + 1) End If To this: ' Parse File Name If Not InStrRev(pstrPath, "\") = 0 Then FileName = Mid(pstrPath, InStrRev(pstrPath, "\") + 1) Else 'NGB 30/7/2013: Not all browsers pass a full path, some pass filename only (Chrome) FileName = pstrPath End If To fix the bug.

    • I use Chrome almost exclusively

      Posted by Leonard on 09/18/2014 11:49pm

      Thanks. This fix worked for me.

      • resolve for Firefox

        Posted by kim on 03/21/2016 09:05am

        confirming this bug also fixes Firefox. thx

  • De haute qualité, redresseurs ghd pas cher est le favori des jeunes

    Posted by lszouc553 on 07/16/2013 11:06am

    Le ressort de la boutique, il est beaucoup Cheap GHD Norge.Our lisseur ghd pas seulement pas cher mais la qualité est Veldig soutien-gorge, est la meilleure product.These ghd pas cher du monde a Flot différent versjoner av ghd stylers cheveux y hjelpe skjønnhet bevisst en y Öppna son Utseende de rêve . Ils sont conçus pour y do coiffure oppleve un grand, avec des résultats étonnants merkbart. Nous consacrons-nous ici å servir chaque client avec lisseur ghd produit beste et Best service.and ces ghd droit Rod Price mer tiltrekke you.We pense que vous nageoire vos lisseur ghd pas cher de favoris. [url=http://ghdpascherfer.webgarden.es/]lisseur ghd pas cher[/url] Si grande est la demande de rose ghd que dans l'approche de la saison des fêtes, les vendeurs sur eBay sont en mesure de facturer jusqu'à 200 £ pour un ghd rose. C'est un énorme £ 65 par rapport au prix de vente conseillé pour le rose ghd! En tant que tel, puisque l'aide ghd pink lever des fonds, ce qui pourrait être un facteur décisif dans les choix d'achat des gens. Mais peut-être une raison plus importante est qu'un grand nombre de femmes aiment des choses roses. Par conséquent, il n'est pas surprenant que, lorsque sortit ghd ghd pink, ce serait quelque chose qui tuerait à posséder! [url=http://ghdpascherferfr.webgarden.com/]ghd pas cher[/url] Troisièmement, ils ont également arrondis barils qui peuvent faire un fer GHD plus polyvalent que beaucoup d'autres types d'appareils de coiffure sur le marché. Si vous souhaitez modifier votre chevelure est souvent avantageux d'utiliser défrisants ghd peut aussi créer des vagues, sauts et loops.Endelig, vous devez sélectionner un fer GHD est conçu pour une utilisation dans une explosion ou frange. GHD IV styler Mini est parfait pour beaucoup moins de cheveux. Combinez ces excellentes caractéristiques redresseurs les plus complets, mais il est plus facile à utiliser sur des petits morceaux de hair.Maybe vous savez ce ghd lisseur

  • Cheap Oakley Big Taco online store

    Posted by wmznldzpc on 06/24/2013 11:54am

    fake ray ban ,Oakley sunglasses is a good brand sunglasses while using highest quality of materials, the choice of Oakley, sunglasses, Oakley sunglasses, each many styles and colors. Today, Oakley in the world already has a lot more than 600 patents and 800 registered trademarks, product of glasses is dizzying. Oakleys Clearance ,Oakley, Sunglasses would you expect from your world leader in performance and innovative technology, unmatched processing towards the smallest detail, there is absolutely no trouble, just change a new lens group. Oakleys will undoubtedly be considered one of their unique class, has become the boom of an trend, they've already found many of the popular Hollywood performers. Cheap Oakley Rada ,Continuous development, in order that a good posture, the comparison in another article. The sun shine, including ultraviolet illumination, and other alike on the sun. The right pair of designer sunglasses in these two different, the thing is, reports of feeling if you live inside hot sun day of outdoor great distance. It is worth noting: if your frame or lens contaminated dust, sweat, grease, cosmetics and other warm water cleaning with a neutral detergent. A range of Websites Providers with the simplicity of the customer's request, select one of several people likely to end up accurate and appropriate glasses and identity. In fact, all through the Oakley sunglasses provide 100% UVA and UVB protection. Even non-colored fashion Oakley sunglasses provide same Ultraviolet protection. In addition to the design of top speed and excellence of the development of high-protection framework. Oakley will be worth your time and money of said and done, the people's lifestyle, sports or polarized sunglasses can buy the suitable product manufacturers from this. In year retro massive construction projects, Oakley glasses essential clothing accessories, and sometimes keep to the fashion trends go, sometimes they lead the popularity. Oakley sunglasses at least change the color of why people love the object itself, more real, natural landscape, but additionally to avoid glare. Oakley sunglasses they HDO (high-definition optical) is well know, and they continue to use this breakthrough technology inside their design. Oakley sunglasses sales with lots of styles so that you can choose. We provide Iridium lens coating to balance light transmission to offer the most effective visual type of the targeted environment.

  • GHD IV Styler – min Perfekt verktøy

    Posted by pletchermtx on 06/14/2013 02:25pm

    [url=http://www.rettetangnorgenews.net/]ghd rettetang[/url] GHD rettetang sørger for at stylingen ikke blir for varm for farget hår. Det er faktisk ganske enkelt: Forskjellige hårtyper trenger forskjellige temperaturer for å reagere på styling. Varmen går lettere gjennom tynt hår enn tykt hår. Derfor har Satin Hair 7 Colour rettetang en intuitiv varmejustering som lar deg forhåndsinnstille temperaturen nøyaktig etter hårtypen (tynt, normalt, tykt hår). Og selv om du bruker effektknappen for å temme uregjerlige hårlokker, så vil du ikke utsette håret ditt for temperaturer på over 200 °C. Få flotte stylingresultater uten fare for for høye temperaturer og nyt den flotte hårfargen din lenger. [url=http://www.rettetangnewsnorge.com/ghd-omsorg]ghd rettetang pris[/url] Varmen går lettere gjennom tynt hår enn tykt hår. Derfor har Satin Hair 7 Colour rettetang en intuitiv varmejustering som lar deg forhåndsinnstille temperaturen nøyaktig etter hårtypen (tynt, normalt, tykt hår). Og selv om du bruker effektknappen for å temme uregjerlige hårlokker, så vil du ikke utsette håret ditt for temperaturer på over 200 °C. Få flotte stylingresultater uten fare for for høye temperaturer og nyt den flotte hårfargen din lenger.Tvert imot: de hindrer fuktighetstap fra stylingen ved å påføre unike satengioner til håret ditt! Disse negativt ladde ionene fester seg til det positivt ladde håret ditt og reduserer tørt, krusete hår og tiltrekker fuktighetspartikler fra lufta og sender dem dit hvor håret trenger det mest. [url=http://www.rettetangnorgenews.net/]rettetang ghd[/url] Rettetangen har roterende ledningfeste og tre ulike temperaturinnstillinger for ulike funksjoner og hårtyper, der makstemperaturen er 230 °C.Med den globale spenningsomformeren for 120-240V er rettetangen også perfekt å ha med på reisen, og du oppbevarer den sikkert i den medfølgende varmebestandige vesken i luksuriøs design.Elegant rettetang Paris som du både kan glatte og krølle håret med.

  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date