I am working in C#, so forgive me using that instead of VB.If I do a straight conversion of the VB code to C# (also in VS 2008 Express):
//Dim pMxDoc As IMxDocument = DirectCast(m_app.document, IMxDocument)
IMxDocument mxDocument = ArcMap.Document;
//Dim pMap As IMap = pMxDoc.FocusMap
IMap map = mxDocument.FocusMap;
//Dim pMapDoc As IMapDocument = pMap
IMapDocument mapDocument = map as IMapDocument;
//Dim mxdPathName As String
//mxdPathName = strDefaultWorkspace & "\" & frmWSIn.txtMapDocName.Text
string mxdPathName = "C:/temp/testsave.mxd";
//pMapDoc.SaveAs(mxdPathName)
mapDocument.SaveAs(mxdPathName, false, false);
I get the following runtime exception on the SaveAs call:Object reference not set to an instance of an object.If I don't use the currently loaded map, and instead open an existing one, the SaveAs works:
IMapDocument mapDocument = new MapDocumentClass();
mapDocument.Open("C:/temp/mymap.mxd", "");
string mxdPathName = "C:/temp/testsave.mxd";
mapDocument.SaveAs(mxdPathName, false, false);
So, I suppose the question is: how do we get a reference to ArcMap's current map as an IMapDocument?I tried:
IMapDocument mapDocument = (IMapDocument)ArcMap.Document;
string mxdPathName = "C:/temp/testsave.mxd";
mapDocument.SaveAs(mxdPathName, false, false);
That results in the following runtime exception on the SaveAs call:Not implemented (Exception from HRESULT: 0x80004001 (E_NOTIMPL)).According to the API reference, the MxDocument CoClass implements IMapDocument, so I am stumped.-Jeff