access .Net Hashtable in Coldfusion
Posted by wrvishnu on September 28, 2007
.Net hashtable can be used as a Structure in coldfusion, below snippets explains the steps
This Sample is for accessing the .Net Hashtable in Coldfusion
Steps to be Followed
Create a Class Library which generate Hashtable (collection or structure)
Call the .Net method from Coldfusion
.Net Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;public class HashTableDemo
{public HashTableDemo()
{
}public Hashtable getInfo()
{
Hashtable HTdemo = new Hashtable();HTdemo.Add("Name","Vishnuprasad" );
HTdemo.Add("Age", 29);
HTdemo.Add("Sex", "Male");
HTdemo.Add("Mobile", 9884077182);
HTdemo.Add("Email", "demo@demo.com");
HTdemo.Add("SkillSet", "Coldfusion, .Net , SQL Server, ORacle , Business Objects");
return HTdemo;
}
}
Above code will generate the DLL which needs to be used in Coldfusion as mentioned below with the path
CFM Code
<cfobject
type = "dotnet"
name = "Htdemo"
class = "HashTableDemo"
assembly ="d:/Vishnu/HashTableDemo.dll">
<cfset HCollection = #Htdemo.getInfo()#><cfoutput>
<table cellpadding = "2 " cellspacing = "2 "><!--- In cfloop, use item to create a variable
called person to hold value of key as loop runs --->
<cfloop collection = #HCollection# item = "Value">
<TR>
<TD><strong>#Value#</strong></TD>
<TD>#StructFind(HCollection, Value)#</TD>
</TR>
</cfloop>
</table>
</cfoutput>