Quick Tip on Resolving UNC Paths in ColdFusion

A few months back, we moved all of our user-generated content to a file share, and had to rewrite some of our code to use the new UNC path to the files. As with most things ColdFusion, it's best to let the application server do the hard work for you, so instead of writing out the full UNC path to files in a <cffile> tag, you should use the expandPath() function instead. This is a really good idea if, at some imaginary point in the future, the path to your file share changes. (File shares never change locations in a network, right?)

One thing that tripped me up on more than one occasion was the need to run expandPath() on the directory that points to the file share, and not another directory like webroot or wherever you might be storing files on the actual ColdFusion server. So instead of doing this:

<cfset pathToFiles = expandPath("/") & "fileShareDirectory/someOtherDirectory" />

you have to do this:

<cfset pathToFiles = expandPath("/fileShareDirectory/someOtherDirectory" />

Otherwise, ColdFusion won't be able to resolve the actual path to the file share directory via the appropriate UNC path. It will look for a directory called "fileShareDirectory" in the webroot, even if there's an alias set up at the operating system level to point to the actual file share on another server.

Comments
air jordan shoes's Gravatar Cool stuff. Thank you this info. It happens to be just what I have already been in search of the past few a short time
# Posted By air jordan shoes | 5/21/12 5:25 AM
BlogCFC was created by Raymond Camden.

Creative Commons License
The content on http://www.iterateme.com/ is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.