Programmatically Determine Bartender Version Of .btw File フォローする

0
Avatar
Legacy Poster

We have various customers using our web application (some hosted at the customer's site, some hosted by us) and the versions of bartender used by the customers can vary from 9.4 to 10.1.  I'd like to detect what version of bartender was used to create a .btw file so if a customer tries to print from a .btw file that was made with a later version of bartender than they have installed we can put up a message to this effect.

 

Alternatively, is there a way to get the ODBC connection properties of a .btw file that is not version dependent?  I've found that using 

 

LabelFormat labelFormat = new LabelFormat(LabelFormatPath);

to open a .btw file will successfully open a label created in v10.1 from a machine that is running v9.4, but doing

 

            using (Engine btEngine = new Engine())
            {
                // Start the BarTender print engine.
                btEngine.Start();

                // Initialize the format document
                // (create a format with query prompts to use this example).
                LabelFormatDocument btFormat = btEngine.Documents.Open(LabelPath);

 

results in a COM exception and the message "The Format file could not be found. Try checking the spelling of the file name or try another format file name [file path]".

 

I'm doing the btEngine.Documents.Open so I can get the ODBC connection's Name and SQLStatement values.

3 コメント

0
Avatar
Ian Cummings
モデレータ
コメントアクション Permalink

I don't think this is directly supported in the API.  However, each BTW file, although a binary file, has a plain text header that contains this file version information that you're after.  I guess you could write a function to read this info in a text stream, and get the info that way instead.  Not particularly clean, but should get the job done.

0
Avatar
Legacy Poster
コメントアクション Permalink

Hi Ian, thanks for the reply =)

 

I'll look into the header thing.  Is it accurate to say, then, that the only way to get the ODBC connection properties stored in the file is through the Engine.Documents.Open() as in:

 

    private string getODBCName(string LabelPath, ref string LabelSQL)
    {
        string connectionName = string.Empty;

        using (Engine btEngine = new Engine())
        {
            // Start the BarTender print engine.
            btEngine.Start();

            // Initialize the format document
            // (create a format with query prompts to use this example).
            LabelFormatDocument btFormat = btEngine.Documents.Open(LabelPath);

            // Print the name and type of each database connection.
            // (foreach implicitly uses GetEnumerator).
            foreach (Seagull.BarTender.Print.Database.DatabaseConnection connection in btFormat.DatabaseConnections)
            {
                connectionName = connection.Name;
                LabelSQL = ((Seagull.BarTender.Print.Database.ODBC)connection).SQLStatement.Replace("\r\n", " ");
            }

            // Close the current format without saving.
            btFormat.Close(SaveOptions.DoNotSaveChanges);

            // Stop the BarTender print engine.
            btEngine.Stop();

            return connectionName;
        }
    }

 

Or is there another way that uses API code that is not version-sensitive?

 

Thanks!

0
Avatar
Ian Cummings
モデレータ
コメントアクション Permalink

Not that I know of myself.

サインインしてコメントを残してください。