This looks interesting but I cannot see how I can use this in a Cold Fusion Template.
Not familiar enough with VBA and how to integrate into a web page.
Main Topics
Browse All TopicsI need to determine if a file is open by another application before I attempt to write to that file. The file is an Excel spreadsheet. Not sure if CFFile has a way of testing this or would I need some type of custom tag
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
you could hook into java, which should exist on your system if you're running coldfusion...
<cfscript>
file = createObject("Java", "java.io.File").init("ABSO
try{
channel = createObject("Java", "java.io.RandomAccessFile"
writeOutput("File is not open...");
channel.close();
channel = "";
}
catch(any err){
writeOutput("File IS open...");
}
</cfscript>
basically java will throw an exception if the file is open saying can't find the file, it may be in use by another process...
hence the try/catch to handle the exception and determine if the file is open or not...
Java is indeed installed on this server.
This does have promise but it always throws an exception - java.io.FileNotFoundExcept
I tried with single backslash, double backslash, forward slash, double forward slash.
I have set the file access to "everyone" with full control. Not sure what is wrong.
Here is the simple template I am using to test.
<html> <head>
<title>...</title>
</head>
<body>
<cfscript>
file = createObject("Java", "java.io.File").init("c:/P
try{
channel = createObject("Java", "java.io.RandomAccessFile"
writeOutput("File is not open...");
channel.close();
channel = "";
}
catch(any err){
writeOutput("File IS open...");
}
</cfscript>
After the script
</body></html>
Did your requests and still the same - always fails.
Here is the entire exception message:
11/11 07:31:20 user RDSServlet: C:\Websites\Geometrics\Quo
java.io.FileNotFoundExcept
at java.io.FileInputStream.op
at java.io.FileInputStream.<in
at coldfusion.rds.FileServlet
at coldfusion.rds.FileServlet
at coldfusion.rds.RdsServlet.
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at coldfusion.rds.RdsFrontEnd
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at coldfusion.bootstrap.Boots
at jrun.servlet.ServletInvoke
at jrun.servlet.JRunInvokerCh
at jrun.servlet.JRunRequestDi
at jrun.servlet.ServletEngine
at jrun.servlet.jrpp.JRunProx
at jrunx.scheduler.ThreadPool
at jrunx.scheduler.ThreadPool
at jrunx.scheduler.ThreadPool
at jrunx.scheduler.WorkerThre
Well the first one failed with this error:
The getCanonicalPath method was not found.
Either there are no methods with the specified method name and argument types, or the getCanonicalPath method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that matched the provided arguments. If this is a Java object and you verified that the method exists, you may need to use the javacast function to reduce ambiguity.
The error occurred in C:\Websites\Geometrics\Quo
17 : <cfscript>
18 : file = createObject("Java", "java.io.File").init("C:\P
19 : writeoutput(file.getCanoni
20 : </cfscript>
No reason to try the second
Are you able to move the xls file to the desktop, and adjust the path specified when creating the File object with the new path, and have any success in not returning the file not found?
Something seems off. I've tested a few different things and it seems to be working fine. Where in relation to your web application will this file reside once you app is completed?
Can you access this file through any of your current coldfusion apps?
Tried moving to the desktop with same failure.
So I then put in the webserver root location and still fails. I can use Cold Fusion to read that file with cfx_excel. That seems fine - The code is below.
I want to eventually have the file on another server. Currently the cfx_excel also works fine opening a file on a different server.
<cfscript>
file = createObject("Java", "java.io.File").init("C:\W
try{
channel = createObject("Java", "java.io.RandomAccessFile"
writeOutput("File is not open...");
channel.close();
channel = "";
}
catch(any err){
writeOutput("File IS open...");
}
</cfscript>
<!--- <cfscript>
file = createObject("Java", "java.io.File").init("C:\D
writeoutput(file.getCanoni
</cfscript> --->
<cfx_excel action="read"
File="C:\Websites\Geometri
Sheet="Sheet1"
Result="recordset3"
Formula="process"
StartRow="1"
EndRow="3"
StartCol="A"
EndCol="C"
HeaderRow="1"
ProcessMerged="true"
DecimalDigit="2">
<cfdump var="#recordset3#">
</body></html>
I'll take a another look at this in a little bit, currently on my laptop I'm running railo 3 express and its working fine, at home I have adobe cf and IIS. Maybe there are some differences causing an issue reading the file. Seems odd that cfx_excel can access the file but native java can't, cf is running on java and so is cfx_excel.
The only other suggestion for now it try relative pathing and see if java.io.File can resolve it. I haven't tried it yet, but may be possible.
yeah actually I should say rather than using the full path from drive letter specify a path relative to your web root.
Example:
instead of specifying "C:\Inetpub\wwwroot\myfile
try using "/myfiles/Book1.xls"
that'd probably work before ../Book1.xls, but it wouldn't hurt to try both...
You got my curiosity now on why what I'm doing is working an you can't seem to get it working there and why cfx_excel would work with "C:\Websites\Geometrics\Qu
Need to reverse engineer the cfx_excel!!
I even put the file in the root of the website and several other places and it still fails.
Interesting that I can run CFFILE and it reads the file fine.
When it cannot find the file (mispelled) it returns the same java.io.FileNotFoundExcept
Sorry it's taken a bit of time to post again on here, I use to be on here all the time, then started getting pretty busy with work. Anyway had some time to tinker around with this and found something that may be interesting, or at least why what I posted above worked for me and it didn't work for you...
Basically it comes down to using the variable name "file" in the scripts I posted above, I used "file" to create a handle to the "java.io.File" object. In Railo 3 it didn't confuse this with the localScope variable "file" which is a local scope for file operations dealing with <cffile>. When I tried my script out on CF/Jrun/IIS, I experienced issues when instantiating the "java.io.RandomAccessFile"
So after renaming "file" to "fileObj", it worked on CF/Jrun/IIS as well.
So give this a try and see how it works, just use the same path you would use with cfx_excel.
Here's the code again...
Note: Rather than output the error in the code below...
//other code above
catch(any err){
writeOutput(err);
}
it could simply be this...
//other code above
catch(any err){
writeOutput("File IS Open...");
}
Also just an FYI, I checked out the source code for Jakarta POI, which is under the hood in cfx_excel, it uses "java.io.File" to read in the path for the excel file... but because it wasn't running into naming conflicts, it didn't have a problem ;o)
Good luck...
ok and last post... ;o)
I would also check for the existence of the file you want to read in before instantiating the object "java.io.File".
var filePath = "your file path here";
var fileObj = "";
var err = "";
if(fileExists(filePath)){
fileObj = createObject("Java", "java.io.File").init(fileP
try{
//see if file is open
}
catch(any err){
// catch/handle exception for an open file...
}
}
Business Accounts
Answer for Membership
by: ZvonkoPosted on 2009-11-09 at 09:31:44ID: 25778034
Here the base info page: http://www.xcelfiles.com/I sFileOpen. html