Blog posts made on 30-May-07
GetDriveInfo() UDF Powered By .NET

This is an example that I used when demonstrating ColdFusion 8 .NET integration on the recent usergroup tour, and as requested, I am posting it publicly. GetDriveInfo() returns a query containing specifics about the hard drives on your server, it returns all drives unless an optional drive letter is passed to it. GetDriveInfo() uses the .NET System.IO.DriveInfo class (which was introduced in .NET 2, and thus this example requires .NET 2 or 3).

Here is the code:

view plain print about
1<!--- Get drive details for one or all drives --->
2<cffunction name="GetDriveInfo" returntype="query" output="false">
3    <cfargument name="drive" required="no" default="">
5    <!--- Local vars --->
6    <cfset var result=QueryNew("name,type,isready,format,label,totalsize,freespace",
7                            "varchar,varchar,bit,varchar,varchar,double,double")

8    <cfset var sidiClass="">
9    <cfset var drives="">
10    <cfset var i=0>
12    <!--- Get System.IO.DriveInfo class --->
13    <cfobject type=".NET"
14                name="sidiClass"
15                class="System.IO.DriveInfo">

16    <!--- Get drives --->
17    <cfset drives=sidiClass.GetDrives()>
19    <!--- Loop through drives --->
20    <cfloop from="1" to="#ArrayLen(drives)#" index="i">
21        <!--- Check if need this one --->
22        <cfif IS ""
23            OR EQ drives[i].Get_Name()
24            OR (Len( IS 1
25                AND EQ Left(drives[i].Get_Name(), 1))>

26            <!--- Add row --->
27            <cfset QueryAddRow(result)>
28            <!--- Get name, type, and ready flag --->
29            <cfset QuerySetCell(result, "name", drives[i].Get_Name())>
30            <cfset QuerySetCell(result, "type", drives[i].Get_DriveType().ToString())>
31            <cfset QuerySetCell(result, "isready", drives[i].Get_IsReady())>
32            <!--- Get extra details ONLY if ready, or will throw error --->
33            <cfif drives[i].Get_IsReady()>
34                <cfset QuerySetCell(result, "format", drives[i].Get_DriveFormat())>
35                <cfset QuerySetCell(result, "label", drives[i].Get_VolumeLabel())>
36                <cfset QuerySetCell(result, "totalsize", drives[i].Get_TotalSize())>
37                <cfset QuerySetCell(result, "freespace", drives[i].Get_AvailableFreeSpace())>
38            </cfif>
39        </cfif>
40    </cfloop>
42    <!--- Return result --->
43    <cfreturn result>

And here is a simple test example:

view plain print about
1<!--- Test with all drives --->
2<h3>All Drives</h3>
3<cfdump var="#GetDriveInfo()#">
5<!--- Test with just C: drive --->
6<h3>C: Drive</h3>
7<cfdump var="#GetDriveInfo("C")#">
9<!--- Display just space on C: drive --->
10<h3>Free Space On C Drive</h3>
11<cfdump var="#NumberFormat(GetDriveInfo("C").freespace)#">

Read More ›

HostMySite Offering Free CF8 Beta Hosting

HostMySite (actually, they do indeed host my site) is offering free ColdFusion 8 hosting for the duration of the beta. Details posted online.

Read More ›

Gartner: Adobe Appreciates ColdFusion

InfoWorld has posted a great story on ColdFusion 8, and it includes this quote from Gartner:

The ColdFusion upgrade puts to rest questions about Adobe's commitment to the technology after acquiring Macromedia, said analyst Ray Valdes, research director for Internet platforms and Web services at Gartner. "People may have wondered if Adobe appreciated ColdFusion, and I think they do. I think it's part of their enterprise software strategy," Valdes said.

Wonderful! This just made my day (well, on top of the CF8 public beta making my day, of course).

Read More ›

Getting Started With The ColdFusion Debugger

After a 7 year hiatus, ColdFusion once again has an interactive debugger, and this time it is built on top of Eclipse (and uses the same debugging interface as Flex Builder, and other Eclipse plug-ins). If you are interested in taking the debugger for a spin, here's what you need to know to get started:

First of all, you need ColdFusion 8. If you don't have it yet, get it!

You'll also need the ColdFusion 8 Eclipse extensions, and these must be installed (here is some installation help).

Before you can use the interactive debugger you need to enable debugging support in ColdFusion. Here's what you need to do:

  1. Open the ColdFusion Administrator.
  2. Select "Debugger Settings" in the "Debugging & Logging" section.
  3. Check "Allow Line Debugging".
  4. The debugger needs a port to communicate over, if you can't use the default change it (just be sure to use an unused port, and you can't use the port that ColdFusion itself is on).
  5. By default ColdFusion allows up to 5 concurrent debugging sessions, you can raise or lower this value as needed.
  6. Click "Submit Changes", and restart ColdFusion is you are instructed to do so.

Once you enable line debugging it will remain enabled even if ColdFusion is restarted. As a rule, do not enable line debugging on production servers, and you may want to always leave it enabled on development boxes.

Now that debugging is enabled, you need to configure Eclipse to tell it what ColdFusion server to debug against. Servers need to only be defined once, and once defined you may debug against them as needed. You can define as many servers as you need, local and remote, as long as the server has RDS enabled (and you have an RDS login).

The first thing you need to do in Eclipse is define the RDS settings for your ColdFusion server. These settings are used by the debugger, as well as the wizards, RDS panels, and more. To define your RDS connection do the following:

  1. In Eclipse, select Window->Preferences to display the Preferences dialog.
  2. Select ColdFusion in the tree, expand the selection, and select RDS Configuration.
  3. Click New to add a new server, or just select any server to edit it.
  4. Provide a description, host name, port, and login details, and then save. To use your local ColdFusion server specify as the Host Name, 8500 as the Port (if using the integrated HTTP server), leave the Context Root blank, and provide the login information.
  5. Click "Test Connection" to make sure the RDS connection is working, and the click OK.

Once the RDS connection is defined you'll be able to browse data sources in the RDS Dataview tab, view available CFCs in the Services Browser tab, use the wizards, and more. And you'll be able to debug applications, but first ...

Now that your RDS connection is defined, you need to define the ColdFusion servers you wish to debug against. Here is what you need to do:

  1. Locate the Debug button in the toolbar, it's the one with the little green bug on it.
  2. Don't click the button, instead, click the down arrow to the right of it and select "Debug ..." to display the Debug dialog which is used to manage debugging configurations.
  3. The Eclipse debugger is used to debug all sorts of applications created in all sorts of languages, and along the left of the dialog you'll see a list of applications types that can be debugged. Select "ColdFusion Application".
  4. You'll see any defined ColdFusion debugging servers under the "ColdFusion Application" branch. To add a ColdFusion server click the New button (the leftmost one above the list) while you have "ColdFusion Application" selected.
  5. Name this server, and then select the RDS server to use from the drop down list.
  6. If you are debugging against a local server (running on the same machine as Eclipse) you can ignore the mappings section. If ColdFusion is on a remote server then you'll need to define mappings here.
  7. Click "Apply" to save your changes.

Again, servers need to be defined once, and they'll be saved for future use.

To debug your code you can do the following:

  1. Open the ColdFusion file to be debugged in Eclipse.
  2. Set breakpoints as needed by double clicking to the left of the desired line in the vertical bar to the left of the Eclipse editor window. You'll see a little circle appear indicating that a breakpoint has been set. You can also right click in the vertical bar and select "Toggle Breakpoint".
  3. Now you need to switch to the Eclipse Debug view (called a "Perspective" in Eclipsese). If you see a Debug button listed with the Perspectives on the top right of Eclipse, click it. Or, just click the Open Perspective button (or select Windows->Open Perspective) and select "Debug".
  4. Once you are in the Debug perspective start the debugging session. To do this, go back to the dialog where you defined the ColdFusion server (under the Debug button), select the ColdFusion server to debug against, and click the Debug button at the bottom of the dialog.
  5. Eclipse will pause while it opens a debug session, connecting to the specified ColdFusion server. You'll see the connection show up in the Debug window.
  6. Now just open any browser and run your application. When you request a page with a breakpoint, execution will pause, and the debugger will pop up. You'll be able to step through code, view variables and expressions (in the top right panel), see generated server output, and more.
  7. When you are done debugging, you can terminate the debug session by clicking the red square Terminate button.

And that'll do it. I know this seems complex and a lot of work, but the bulk of it is initial setup. Once that setup is complete you'll be able to quickly and easily fire up the debugger on demand and when needed.

Read More ›

Installing ColdFusion 8 Eclipse Extensions

The ColdFusion extensions for Eclipse include RDS panels, a Services Browser panel, a CF Log Viewer, RDS support, help, wizards, and of course the interactive debugger. These extensions are available for download along with ColdFusion 8 and will be distributed with the product when it ships.

To install the Eclipse extensions, do the following:

  1. Start up Eclipse (3.1 or 3.2).
  2. Select Help->Software Updates->Find And Install.
  3. Select "Search For New Features To Install".
  4. Click the "New Archived Site" button.
  5. Brows to select the extensions ZIP file that you downloaded.
  6. Check the feature, and then Finish the installation.
  7. You'll be prompted to restart Eclipse.

Once installed you'll have access to all of the extensions. The Wizards are available under File->New->Other. To display the ColdFusion tabs go to Window->Show View->Other, the tabs will be listed under "ColdFusion", select each tab to show it. You only need to do this once, the next time you start Eclipse the settings will be remembered and the tabs displayed.

Read More ›

CFPDF Blog Now Online

Ahamad Patan, a member of the ColdFusion team in Bangalore, has launched a blog entitled CFPDF, which, as its name suggests, will cover the new PDF support in ColdFusion 8.

Read More ›

Get Your Scorpio NOW!

This just in, the public beta of ColdFusion 8 (aka Scorpio) is up on Labs! Get it now!

Read More ›