Error: The system cannot find the file specified

If a Chilkat method fails because a file was not found, the LastErrorText will contain information such as this:

ChilkatLog: 
LoadFromFile: 
DllDate: Sep 1 2009 
filename: myCert.cer
Failed to open file (2) 
filename: myCert.cer 
currentWorkingDirectory: c:\windows\system32\inetsrv 
osErrorInfo: The system cannot find the file specified. 
WindowsError: 0x2 Failed.

There are two key pieces of information to allow you to know the exact filepath it was trying to open.

  1. The filename (or filepath). In this case we can see it was “myCert.cer”
  2. The calling process’s current working directory. In this case we can see it was “c:\windows\system32\inetsrv”. This is the current working directory for the IIS process.

Every Windows process has a “current working directory”. If your application tries to open a file without specifying a path, then it will be trying to open a file in the current working directory. In the case above, the application was trying to open “c:\windows\system32\inetsrv\myCert.cer”. This is obviously not what the application programmer intended. Nor is it likely that ASP code has permission to create or read files in that directory. The solution is to specify an absolute filepath in the Chilkat method that opens/creates a file, or in this case, to use ASP’s Server.MapPath function to convert from a virtual directory to a physical absolute directory.