Search This Blog

Thursday, 15 May 2008

How to consume a .Net ArrayList in classic ASP

I first followed the procedure to register a .Net assembly using regasm on the web server as below (

  1. Make sure your assembly has a strong name to install it in the GAC
  2. Run regasm /tlb “<path of your assembly>”
  3. Add the assembly to the GAC

This allows your assembly to be accessible in your ASP code to create server side objects

In my example I have a .Net assembly which has a class as below


using System; 
using System.Collections; 
namespace API 
      /// <summary> 
      /// Summary description for Versions. 
      /// </summary> 
      public class Versions 
            ArrayList versions = new ArrayList();
            public Versions() 

            public ArrayList List
                        return versions; 

I initially tried to have a method in my .Net class return an ArrayList, Then I tried to create an object of type “System.Collections.ArrayList” in ASP and iterate the object in ASP, as the array list type definition was not supported when the asp code executed. So I created the class above which had a public property having a type of System.Collections.ArrayList


So now in ASP I did the following and it printed out the arrray list on my asp page

<%@ codePage="65001" %> 
            <title>Test Page</title> 
   2:                   set versions = Server.CreateObject("Versions") 
   3:                   For Each v in versions.List 
   4:                         Response.Write(v & "</br>") 
   5:                   Next 
%> </head> <body></body> </html>

That can be further enhanced in your ASP code to achieve the functionality you need to



No comments: