Coldfusion 8 and .NET – My first Attempt

On January 14, 2008, in ColdFusion, by Anuj Gakhar

We all know Coldfusion8 has some aded functionality for .NET integration. What that basically means is, Coldfusion can now interact with .NET assemblies simply by creating an object. We could always consume .NET webservices in Coldfusion in earlier versions but that had some datatype compatibility problems. In Coldfusion 8, it allows us to access native .NET objects as CFML objects and it also converts data types automatically. That sounds cool enough. So, I decided to go ahead and try it out, just a very little “hello world” kinda example.

My first hurdle was to find out which assembly to consume and which methods it exposes. I could always use CFDUMP once I create the Object but then its always easier to be able to know beforehand what methods are available. I did some search on Google and found out this little tool . It is basically a class browser, explorer, analyzer and documentation viewer for .NET. It allows you to navigate .NET assemblies easily. Once I installed it, this is how it looks like.

Reflector Screenshot

I decided to work with System.IO.Directory as my first example. So this is what I did

<cfobject type=".NET" class= "System.IO.Directory" name="fso">[/xml]

Its that easy, that creates the Object of the .NET assembly available to CF and we can now access all the underlying methods. I wanted to see what the current working directory is, so I did this :-

<cfset cwd = fso.getCurrentDirectory()>
<cfdump var = "#cwd#">[/xml]

That returns C:\ColdFusion8\jnbridge which is the folder where the JnBridge classes sit for accessing .net assemblies.

Next, I wanted to create a directory in one of my folders. So, I did this

<cfset temp = fso.setCurrentDirectory("c:\site") />
<cfset temp = fso.CreateDirectory("cf8iscool") />[/xml]

And it works! Its so easy!

I think this is a great feature to have. I am gonna try out some more examples over the next few days and if I find anything interesting, I will post here. Would like to know if anyone else has tried anything with .NET from CF8.

Tagged with:  

7 Responses to Coldfusion 8 and .NET – My first Attempt

  1. This is really the first working example I have seen. It is pretty cool.

  2. noname says:

    This is the first example for me too.

  3. […] Gakhar has blogged about ColdFusion and .NET integration. Inspired by his example I decided to try it and build real world example. It uses custom assembly […]

  4. […] doing my first example with CF8 and .NET, I got a little excited and wanted to do more with it. I am not really a .NET guy […]

  5. Jenn says:

    I haven’t had the opportunity yet to try anything with .NET from CF8 but it sure is a great feature to have. This is also the first working example I’ve ever seen, it makes it so clear and it does seem easy. I also appreciate the navigability, a very cool example.

  6. kennethg says:

    Coldfusion 8 and .NET? I thought that’s impossible. What a brilliant idea! I will also try that sample myself.

  7. Sophia says:

    This is really pretty good. This is a good example post. Very reliable source, I tried this on my computer and it works. Really amazing! Thanks a lot.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 446 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: