Search Persits Software Knowledge Base

 

Article PS020704100

AspUpload usage under ASP.NET

Problem Description

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.

Solution

1. Enable classic ASP compatibility mode
AspUpload 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:

<%@ Page aspCompat="True" other attributes%>

Failure to do so will result in the run-time error

There is no MTS object context

2. Place ASPUPLOADLib.dll under \bin directory of your app
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.

The file ASPUPLOADLib.dll is included in the download given below. You may also re-create this file using the command-line utility TLBIMP.

3. Use ASPUPLOADLib.IUploadManager type to declare Upload object
Declare and instantiate the main Upload Manager object as follows:

VBScript:

Dim objUpload As ASPUPLOADLib.IUploadManager
objUpload = New ASPUPLOADLib.UploadManager

C#:

ASPUPLOADLib.IUploadManager objUpload;
objUpload = new ASPUPLOADLib.UploadManager();

4. In C#, use Missing.Value for optional arguments
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).

C# 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" %>

4. In C#, shortcuts won't work
A VBscript expression such as

txtName = Upload.Form("name")

must be fully expanded in C#, as follows:

txtName = objUpload.Form.Item("Name").Value;

5. In C#, use + instead of & to concatenate strings
A VBscript expression such as

txtLine = File.Name & "= " & File.Path & " (" & File.Size &" bytes)<BR>"

must be rewritten in C# as follows:

txtLine = objFile.Name + "= " + objFile.Path + " (" + objFile.Size + " bytes)<BR>";

6. Adjust maxRequestLength in web.config if necessary
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:

<system.web>
   <httpRuntime maxRequestLength="15000" />
</system.web>

7. Review code samples
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:

simple_aspx.zip

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.

Created: 7/4/2002 9:02:54 PM
Last Modified: 4/23/2003 6:10:26 PM

Copyright © Persits Software, Inc. 1998 - 2017
For technical support, write to support@persits.com.