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
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
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() ); }
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
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
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