Unfortunately, your method and the method below does not work. If you place a lock on the file you have to wait for the O.S. to release the file. Thus a call FileInUse that returns true can still fail on the file open. The only way is to open the file and lock the file and return that lock.
Why don't you let us know what database you are using, and what do you mean by permanent. Is the database losing data when you close the app, or when you install updates to the application or when? When asking a question you need to be pretty specific as to what the problem is and you might get more help.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
But I get the data from the database and make changes and when I reopen the application the changes are not there, they always were when I used Access why doesn't the information stay in the database, I type it into the form!
[note the joke icon]
Never underestimate the power of human stupidity
The reason that it's doing this is because you have a master version in your solution, and it is set to be copied to the output directory whenever you build the application. This means that you are making changes to your data when the app is running and then losing them when the master overwrites it. Take a look at the Copy to output directory property on the local database file.
If you want it only to appear for some, then you need to write a shell extension, and due to architectural issues with in-process extensions, you should only do so in .Net 4. See this article on MSDN[^].
You have to find all files on your hard drive (google the DirectoryInfo object), and then use XDocument to open them (google the XDocument object). Once you've done that, displaying them all at once could be more than your system could take.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997