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>
Posted in Coldfusion, Coldfusion Blogs | Leave a Comment »
Posted by wrvishnu on September 27, 2007
Creating windows users in Local Machine using coldfusion 8 & .Net
Steps to be Followed :
Create a .Net Class Library to Create Windows NT Userccount in local machine using VB as Language
Write a Coldfuusion Entry form to Enter the necessary information to Create the user account
Write a Coldfuusion Action page to call the .Net Method to create the user account in local windows machine
Code Snippets
CFM Code
Entry form Code
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Entry Form</title>
</head>
<!—
Password needs to be given as Pasword policy set in that machine
Paramenter to be passed
First Parameter : Username
Second Parameter : Password
Third Parameter : Description
Fourth Parameter : FullName
Fifth Parameter : Machine name like WinNT://machinenameNote : As this is Just a sample there is no Validation or exception Handling
This Example will work only in Windows OS ....---><cfform name="Adsample" method="post" action="Act_ADSample.cfm" >
<strong>Username </strong><cfinput required="yes" message="Username Required" name="LclUsername" size="10"><br />
<strong>Password</strong><cfinput required="yes" message="Password Required" name="LclPassword" size="10"><br />
<strong>Description </strong><cfinput required="yes" message="Description Required" name="LclDescription" size="10"><br />
<strong>Full Name</strong><cfinput required="yes" message="Full Name Required" name="LclFullName" size="20"><br />
<strong>Machine name </strong><cfinput required="yes" message="Machine Name Required" name="LclPcName" size="10"><br />
<cfinput type="submit" name="Createuser" value="Create USer">
</cfform>
<body>
</body>
</html>
Actionpage Code
em><cfobject
</cfobject
type = "dotnet"
name = "MDBDTable"
class = "ADintegration.ADintegration"
assembly ="d:/Vishnu/ADintegration.dll">#Dummy1#
.Net Code
Imports System.DirectoryServicesPublic Class ADintegration
Dim outputval As String
Public Function ADuser(ByVal uname As String, ByVal pass As String, ByVal desc As String, ByVal fullname As String, ByVal PCname As String) As String'First(Parameter) : Username
'Second(Parameter) : Password
'Third(Parameter) : Description
'Fourth(Parameter) : fullname
'Fourth(Parameter) : PC name : eg: Winnt://MachinenameDim lblDMBase As String
lblDMBase = PCname
REM opens a connection to the local machine. It does not necessarily need to be
REM the machine the web page is running on.
Dim adsComputer As New DirectoryEntry(lblDMBase)
Dim adsUser As DirectoryEntry
REM Open a connection to the Group
Dim adsGroup As New DirectoryEntry(lblDMBase & "/Users")
REM You can also open the object by:
'Dim adsGroup As DirectoryEntry
'adsGroup.Path = lblDMBase & "/Users"
Try
REM Add a user to the defined computer object
adsUser = adsComputer.Children.Add(uname, "User")
REM Populate the FullName and Description Properties
adsUser.Properties("FullName").Add(fullname)
adsUser.Properties("Description").Add(desc)
REM Set the password (a random password function would be good here).
adsUser.Invoke("SetPassword", pass)
REM Identical to .SetInfo
adsUser.CommitChanges()REM Add the User to the Group
adsGroup.Invoke("Add", New Object() {adsUser.Path.ToString()})
adsGroup.CommitChanges()outputval = "User Created"
Catch ex As Exception
outputval = ex.Message.ToString()
End Try
Return outputval
End FunctionEnd Class
.Net and Coldfusion Templates used in this sample can be get from
http://www.drivehq.com/folder/p2613077.aspx
Posted in Coldfusion, Coldfusion Blogs | Leave a Comment »
Posted by wrvishnu on September 12, 2007
This is a sample code snippet for Coldfusion and .Net intgeration
To access the .net methods first we need to create an object for the .Net Class , after creating the object we can access the methods in that class . Following is a sample code snippet for accessing the .net methods from coldfusion
Steps to work on the samples
Step 1 Copy the Access MDB file into the “D:\LEarning\CFDotNet\Northwind.mdb”
Step 2 Create the .Net Class Library in Visual studio 2005 , below is the code snippet
// This Code is developed in .net 2005
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;public class CfSample{
public CfSample()
{
}
public int SampAdding(int a, int b)
{
int c;
c = a + b;
return c;
}
public int SampSubtract(int a, int b)
{
int c;
c = a - b;
return c;
}
public int SampMultiply(int a, int b)
{
int c;
c = a * b;
return c;
}
public DataTable ACCdatasetMethod()
{
//conn string
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\LEarning\\CFDotNet\\Northwind.mdb" ;
//ConnectionString='//connection
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand(@"SELECT [EmployeeID], [LastName], [FirstName], [Title], [City], [Address], [HireDate], [BirthDate], [TitleOfCourtesy], [Region], [PostalCode], [Country], [HomePhone] FROM [Employees]", connection);
connection.Open();
OleDbDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
return dt;
}
}
}
Step 3 Compile the Visual studio solution
Step 4 Copy the generated DLL file in any path or can use the same path where it got generated
Step 5 Call the .Net method in Coldfusion
<cfobject
type = “dotnet”
name = “MDBDTable”
class = “CfSample”
assembly = “D:/vishnu/CfSample.dll”>
<cfset query11 = MDBDTable.ACCdatasetMethod()>
<cfdump var=”#query11#”>
Please get the sample files from the location http://www.drivehq.com/folder/p2544729.aspx
Posted in Coldfusion | 19 Comments »
Posted by wrvishnu on September 12, 2007
Welcome to my Blog , this is just start , wish to post as many useful information for Coldfusion Developer
Posted in Coldfusion | 1 Comment »