Example Applications - Adobe 38043740 - ColdFusion Standard - Mac Development Manual

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
• Assemblies registered in the DotNetSide.exe.config file must have unique class names. If two or more assemblies
have the same class name, method invocation can result in an error or can give the wrong result. For example, do
not have two DLLs, a.dll and b.dll, that contain the same class name, nam1.name2.MyClass. If you use one DLL and
later want to use another DLL that contains a class that clashes with first, restart the ColdFusion .NET Service if
ColdFusion and .NET both are on the same machine. If they are on the different machines, remove the entry for
the first DLL from the DotNetSide.exe.config file and restart the ColdFusion .NET Service on the Windows
machine hosting the .NET service.

Example applications

The first application example uses a Microsoft .NET system class method directly. The second application example
uses a custom C# class to access Microsoft Word.
Example: Using a .NET class directly
The following example uses the Microsoft .NET System.Net.NetworkInformation.Ping class method directly to ping
servers. This class is supported in .NET version 2.0 and later.
<!--- This function pings the specified host. --->
<cffunction name="Ping" returntype="string" output="false">
<cfargument name="host" type="string" required="yes">
<!--- Local variables --->
<cfset var pingClass="">
<cfset var pingReply="">
<!--- Get Ping class --->
<cfobject type=".NET" name="pingClass"
class="System.Net.NetworkInformation.Ping">
<!--- Perform synchronous ping (using defaults) --->
<cfset pingReply=pingClass.Send(Arguments.host)>
<!--- Return result --->
<cfreturn pingReply.Get_Status().ToString()>
</cffunction>
<h3>Ping Test</h3>
<cfoutput>
127.0.0.1: #Ping("127.0.0.1")#<br>
www.adobe.com: #Ping("www.adobe.com")#<br>
</cfoutput>
Example: Using a custom class to access Microsoft Word
The following ColdFusion application uses a custom C# WordCreator class, and supporting classes in Microsoft Office
and Word DLLs, to create a Word document. The application opens Microsoft Word, writes five copies of the text
specified by the someText variable, and saves the document in the file specified by the filename variable. The
application leaves the instance of Word open.
Note: For an example that uses a .NET System class directly and does not require any cousin .NET code, see the
"Limitations" section of cfobject: .NET object in the CFML Reference.
The second listing shows the WordCreator C# source code. To run this application locally, compile this class and the
Microsoft Interop.Word.dll file, and place them in the C:\dotnet directory. (Alternatively, you can place them
elsewhere and change the paths in the
DLL files, depending on the version of Microsoft Office that you have installed.
The ColdFusion application contains the following code:
attribute.) You could need additional or different Microsoft
cfobjectassembly
Last updated 1/20/2012
1165

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents