Uploading Files with ASP

The VB Component

Now, we can get started on the VB portion of this tutorial. Create a new ActiveX DLL project in VB, and set the Project's name to 'ASPUploadComponent'. Next, create two Classes to the project, and call them cUpload and cFormItem respectively. cUpload's Instancing property should be set to 5 - MultiUse, and cFormItem's should be set to 2 - PublicNotCreatable.

Finally, you need to add a reference to the ASP Type Library. To do this, go to Project|References, and check the box next to Microsoft Active Server Pages Object Library, and the Microsoft Scripting Runtime (so we can use the FileSystemObject). Now we can get coding...!

Debugging an ASP Component
I think you should be warned at this stage that debugging a VB component used in an ASP script is notoriously difficult. You can't simply press F5 to run the component, as it isn't a stand alone executable. Nor can you use the 'Wait for component to be created' option, as IIS isolates any ActiveX components created in your ASP script for security reasons. Unfortunately, this means VB can't gain any debugging information either.

Therefore, your only option is to compile your component each time you make a change. However, it gets worse... When your script accesses the component for the first time, it locks the file. Your OCX file is not unlocked again until the IIS service stops, meaning that each time you want VB to re-compile the component you have to restart IIS (and not just the web you are using either... all of IIS!). To restart IIS, go to Services, select World Wide Publishing Service, and click Restart.

One last thing... if you would prefer to skip the VB coding section, you can download the source code and binaries here. Then, you can skip to this step.

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson