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. ---> |
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 cfobject assembly attribute.) You could need additional or different Microsoft DLL files, depending on the version of Microsoft Office that you have installed.
The ColdFusion application contains the following code:
<cfset filename="C:\dotNet\demo.doc"> |
The C# source for the WordCreator class is as follows:
using System;
|