Search code examples
c#db4o

c# db4o checking for the right database file


I'm writing a small app which uses db4o database.

I want to choose a database file from my disk and load some stuff (classes, fields, etc.). The problem is how to check is this file is a db4o file?

For example, I will choose a not correct db4o file (for ex. .txt file or something another) - how to check that this file has db4o stuff inside? I can't check the files by their extensions, because it won't work (I have few files with extension .yap, few with another extension, few files with no extension and all those files load correctly)

Sorry for my text, maybe you will understand what I want to achieve. Could you help me?


Solution

  • why dont you make some method to check with exception and try putting inside try ... catch ... block and catch (for example)

        public bool Checkdb4oFile(string fileName)
        {
            try
            {
                using (IObjectContainer container = Db4oFactory.OpenFile(fileName))
                {
                    // do nothong;
                }
                return true;
            }
            catch
            {
                return false;
            }
    
        }