This article outlines the steps necessary to make AspUpload work under the Microsoft ASP.NET framework. It also describes some of the problems and issues associated with using AspUpload under .NET.
1. Enable classic ASP compatibility modeAspUpload 3.0 is not a native ASP.NET component. It was written specifically for classic ASP, and it uses many intrinsic ASP objects such as Request. Therefore, you must enable the classic ASP compatibility mode for all pages using AspUpload by setting the aspCompat attribute of the @Page directive to True:2. Place ASPUPLOADLib.dll under \bin directory of your app<%@ Page aspCompat="True" other attributes%>
Failure to do so will result in the run-time error
There is no MTS object context
Create a \bin subdirectory under your ASP.NET application and place the wrapper assembly ASPUPLOADLib.dll in it. Alternatively, you can place this file in the Global Assembly Cache.3. Use ASPUPLOADLib.IUploadManager type to declare Upload objectThe file ASPUPLOADLib.dll is included in the download given below. You may also re-create this file using the command-line utility TLBIMP.
Declare and instantiate the main Upload Manager object as follows:4. In C#, use Missing.Value for optional argumentsVBScript:
Dim objUpload As ASPUPLOADLib.IUploadManager
objUpload = New ASPUPLOADLib.UploadManagerC#:
ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager();AspUpload's main "workhorse" Save method takes 3 optional arguments. In many cases you will be using only the first argument (path) or none at all (if saving to memory).4. In C#, shortcuts won't workC# requires all three arguments to be specified. Use the expression Missing.Value for arguments you do not wish to use:
objUpload.Save("c:\\upload", Missing.Value, Missing.Value);
You must import the namespace System.Reflection to use the Missing object:
<%@ Import Namespace="System.Reflection" %>
A VBscript expression such as5. In C#, use + instead of & to concatenate stringstxtName = Upload.Form("name")
must be fully expanded in C#, as follows:
txtName = objUpload.Form.Item("Name").Value;
A VBscript expression such as6. Adjust maxRequestLength in web.config if necessarytxtLine = File.Name & "= " & File.Path & " (" & File.Size &" bytes)<BR>"
must be rewritten in C# as follows:
txtLine = objFile.Name + "= " + objFile.Path + " (" + objFile.Size + " bytes)<BR>";
The upload limit is set to 4MB (4096) by the httpRuntime section of the machine.config file. You can change this setting to affect all applications on your site, or you can override the settings in your application-specific web.config as follows:7. Review code samples<system.web>
<httpRuntime maxRequestLength="15000" />
</system.web>
We have rewritten the code samples Form1.asp/UploadScript1.asp, Form2.asp/UploadScript2.asp, and Form3.asp/UploadScript3.asp in C#. Click on the following link to download the .aspx versions of these code samples, along with the wrapper assembly ASPUPLOADLib.dll:Problems and Issues
It appears that the client-side progress bar functionality of AspUpload 3.0 no longer works under ASP.NET due to the way ASP.NET handles large posts. We will continue to investigate this issue and post our findings on this web site.