Join 34,000+ subscribers and receive articles from our
blog about software quality, testing, QA and security.

The system cannot find the path specified



I am trying to resolve an issue of the file protocol not writing a log file because the directory specified for the log does not exist.
In that case I want to try creating that directory and then try to open the log again (or, if that’s not possible, I want to check first and create the directory if it does not exist).

What is the best approach?

I could try to parse the connections myself, extract the directory part and do that check, but I don’t want to duplicate anything that maybe SmartInspect already does.



I think the best solution would be to ensure that the directory exists before enabling the SmartInspect object. If you are building the connections string directly in your application, you should already have the directory and could issue a ForceDirectory call. If you are using configuration files and your application does not necessarily know the directory of the log file, you could use the new connection variables feature. Connection variables let you use variables in connection strings and define those variables in your application. It basically works as follows:

Then, in your application, you can define dir as follows:

This gives you some flexibility in how you handle the directory. This way you can also check for the directory before enabling the SmartInspect object and create it when necessary.

Also, I will make sure to add a feature request to automatically create the directory for a log file directly in the file protocol.