Add-In to get current map version

659
9
01-07-2011 06:56 AM
PaulSchneider
Occasional Contributor
I'm creating an ArcMap Button add-in (VB.NET) that needs to (among other things) determine what version the current Map Document is (v9.3, v10.0, etc.)  The following code throws an exception; all documentation that I have read indicates that I should be getting these version numbers/values using the .getVersionInfo method.  What have I done wrong?

   Private Sub checkVersion()
        Dim pMapDocument As IMapDocument
        Dim vMissing As Boolean
        Dim vMajor As Integer
        Dim vMinor As Integer
        Dim vRevision As Integer
        Dim vBuild As Integer

        pMapDocument = CType(My.ArcMap.Document, IMapDocument)

        Try
            pMapDocument.GetVersionInfo(vMissing, vMajor, vMinor, vRevision, vBuild)
            MsgBox(vMajor & "." & vMinor & "." & vRevision & " " & vBuild)
        Catch ex As Exception
            MsgBox("Didn't work")

        End Try
       
        verChecked = True

    End Sub
0 Kudos
9 Replies
VivekPrasad
Occasional Contributor
I'm creating an ArcMap Button add-in (VB.NET) that needs to (among other things) determine what version the current Map Document is (v9.3, v10.0, etc.)  The following code throws an exception; all documentation that I have read indicates that I should be getting these version numbers/values using the .getVersionInfo method.  What have I done wrong?

   Private Sub checkVersion()
        Dim pMapDocument As IMapDocument
        Dim vMissing As Boolean
        Dim vMajor As Integer
        Dim vMinor As Integer
        Dim vRevision As Integer
        Dim vBuild As Integer

        pMapDocument = CType(My.ArcMap.Document, IMapDocument)

        Try
            pMapDocument.GetVersionInfo(vMissing, vMajor, vMinor, vRevision, vBuild)
            MsgBox(vMajor & "." & vMinor & "." & vRevision & " " & vBuild)
        Catch ex As Exception
            MsgBox("Didn't work")

        End Try
       
        verChecked = True

    End Sub


Hi,

Please try the below sample code in OnClick event of Add-In

Try
            Dim vinms As Boolean
            Dim imaj As Integer, imin As Integer, irev As Integer, ibuild As Integer
           
            Dim pMapDoc As IMapDocument
            pMapDoc = New MapDocument()

            pMapDoc.Open("E:\vara\Untitled.mxd") 'Change the path to your mxd's path

            pMapDoc.GetVersionInfo(vinms, imaj, imin, irev, ibuild)

            MsgBox(vinms & vbNewLine & imaj & vbNewLine & imin & vbNewLine & irev & vbNewLine & ibuild)
        Catch ex As Exception
            MsgBox(ex.Message.ToString())
        End Try

I tried this and working fine.
0 Kudos
PaulSchneider
Occasional Contributor
I expanded on your suggestion to include a GetActiveDocumentPath snippet and am getting results... but the results I am getting are of no help.

I get a value of True for versionInfoMissing and empty values (-1) for IMajor, IMinor, IRevision and IBuild.

I am not getting any version Information returned for any of my existing MXDs.

One step forward... two back...

Any other thoughts??   Essentially I need to know if a currently open map was saved in version 10 yet or not.


Thanks-
0 Kudos
JeffreyHamblin
New Contributor III
I tried some quick tests of GetVersionInfo in a C# Add-In, and see the same problem.

If I cast the current IMxDocument to an IMapDocument, it results in a "Not implemented" exception on the GetVersionInfo call.

If I use IMapDocument.Open on the path to either the current document or a hard-coded path to a different existing document, the GetVersionInfo call succeeds, but returns true, -1, -1, -1, -1.

I will poke around a bit more tomorrow...

-Jeff
0 Kudos
VivekPrasad
Occasional Contributor
I tried some quick tests of GetVersionInfo in a C# Add-In, and see the same problem.

If I cast the current IMxDocument to an IMapDocument, it results in a "Not implemented" exception on the GetVersionInfo call.

If I use IMapDocument.Open on the path to either the current document or a hard-coded path to a different existing document, the GetVersionInfo call succeeds, but returns true, -1, -1, -1, -1.

I will poke around a bit more tomorrow...

-Jeff


Hi,

I again ran the code that I have posted earlier, and got correct results.
The output that I got is

vinms, imaj, imin, irev, ibuild
False   10    0     0     2414

I tried for the current map document and also some existing documents. I got the correct result.
Could you post the code you are using?
0 Kudos
JeffreyHamblin
New Contributor III
Here's the C# code I used, called from OnClick of a button:

private void Tests_GetVerInfo()
{

    bool isMissingVerInfo = true;
    int majorVer = 0;
    int minorVer = 0;
    int releaseVer = 0;
    int buildVer = 0;

    // **The following method results in an exception at runtime:**
    //IMapDocument mapDocument = ArcMap.Document as IMapDocument;
    //mapDocument.GetVersionInfo(ref isMissingVerInfo, ref majorVer,
    //        ref minorVer, ref releaseVer, ref buildVer);


    // **This method succeeds but does not get version, reports missing version info**
    string docPath = GetActiveDocumentPath(ArcMap.Application);
    //string docPath = "C:/Temp/Test.mxd";
    IMapDocument mapDocument = new MapDocumentClass();
    mapDocument.Open(docPath, "");
    mapDocument.GetVersionInfo(ref isMissingVerInfo, ref majorVer,
            ref minorVer, ref releaseVer, ref buildVer);
    mapDocument.Close();


    MessageBox.Show(
        docPath + "\n" + 
        isMissingVerInfo.ToString() + "\n" + 
        majorVer.ToString() + "\n" +
        minorVer.ToString() + "\n" +
        releaseVer.ToString() + "\n" +
        buildVer.ToString()
        );
}


Using VS2008 Express and ArcGIS 10.

-Jeff
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Here's the C# code I used, called from OnClick of a button:

private void Tests_GetVerInfo()
{

    bool isMissingVerInfo = true;
    int majorVer = 0;
    int minorVer = 0;
    int releaseVer = 0;
    int buildVer = 0;

    // **The following method results in an exception at runtime:**
    //IMapDocument mapDocument = ArcMap.Document as IMapDocument;
    //mapDocument.GetVersionInfo(ref isMissingVerInfo, ref majorVer,
    //        ref minorVer, ref releaseVer, ref buildVer);


    // **This method succeeds but does not get version, reports missing version info**
    string docPath = GetActiveDocumentPath(ArcMap.Application);
    //string docPath = "C:/Temp/Test.mxd";
    IMapDocument mapDocument = new MapDocumentClass();
    mapDocument.Open(docPath, "");
    mapDocument.GetVersionInfo(ref isMissingVerInfo, ref majorVer,
            ref minorVer, ref releaseVer, ref buildVer);
    mapDocument.Close();


    MessageBox.Show(
        docPath + "\n" + 
        isMissingVerInfo.ToString() + "\n" + 
        majorVer.ToString() + "\n" +
        minorVer.ToString() + "\n" +
        releaseVer.ToString() + "\n" +
        buildVer.ToString()
        );
}


Using VS2008 Express and ArcGIS 10.

-Jeff


  public override void OnClick()
        {
            try
            {

                IMapDocument pMapDocument;

                pMapDocument = new MapDocumentClass();

                pMapDocument.Open(@"C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\Server\data\New Folder.mxd", "");

                bool bMissing = true;

                int lMajor = 0;
                int lMinor = 0;
                int lRevision = 0;
                int lBuild = 0;

                pMapDocument.GetVersionInfo(ref bMissing, ref lMajor, ref lMinor, ref lRevision, ref lBuild);

                if (bMissing == true)
                {
                    MessageBox.Show(lMajor + "." + lMinor + "." + lRevision + "." + lBuild);
                }

            }
            catch (Exception exp) { }
        }
0 Kudos
JeffreyHamblin
New Contributor III
Hi Venkat,

I cut and pasted your C# code into a test app. The only thing I changed was replacing the MXD path with a valid one for my system. The result was a message box with:
-1.-1.-1.-1

Which is the same result as my code.

I have tried this with several different MXDs. So either there is no ESRI version info in any of these MXDs, or something isn't working right with IMapDocument.GetVersionInfo or the way our code is using it.

Like I wrote previously -- I haven't spent much time on this. When I get a chance I will look into it further, unless someone else can point out the problem.

-Jeff
0 Kudos
Venkata_RaoTammineni
Occasional Contributor
Hi Venkat,

I cut and pasted your C# code into a test app. The only thing I changed was replacing the MXD path with a valid one for my system. The result was a message box with:
-1.-1.-1.-1

Which is the same result as my code.

I have tried this with several different MXDs. So either there is no ESRI version info in any of these MXDs, or something isn't working right with IMapDocument.GetVersionInfo or the way our code is using it.

Like I wrote previously -- I haven't spent much time on this. When I get a chance I will look into it further, unless someone else can point out the problem.

-Jeff


Tell me like what exactly your looking for ...map document current version ...right ?
0 Kudos
PeterGranberg
New Contributor III
I tried some quick tests of GetVersionInfo in a C# Add-In, and see the same problem.

If I cast the current IMxDocument to an IMapDocument, it results in a "Not implemented" exception on the GetVersionInfo call.

If I use IMapDocument.Open on the path to either the current document or a hard-coded path to a different existing document, the GetVersionInfo call succeeds, but returns true, -1, -1, -1, -1.

I will poke around a bit more tomorrow...

-Jeff


I experience the exact same problem. I use an ArcGIS Engine 10.1 application in which the user can browse to a mxd-document to apply another template to the PageLayout. I need to validate that the selected mxd-file is 10.0 or 10.1. It is kind of strange, because the GetVersionInfo method give me correct version numbers when I select an old 9.3.1 mxd-file. Im using the exact same code. From an ArcGIS Desktop 10.1 installation, I have created 10.0, 9.3, 9.2 and 8.3 mxd documents using "save a copy", but the call fails for all documents by returning true, -1, -1, -1, -1. I have even created a new 9.3 document with 9.3 Desktop installation but the call to GetVersionInfo fail the same way.

Can anyone bring some light on this issue?

/Peter
0 Kudos