IMapDocument from application

475
4
04-21-2010 09:09 AM
by Anonymous User
Not applicable
Original User: abrown

Hi All,

I'm trying to get a reference to the current MXD so I can save it to disk before making a backup copy.  I tried the following snippet from inside a BaseCommand class I created.

IMapDocument mapDoc = m_application.Document as IMapDocument;
mapDoc.Save(mapDoc.UsesRelativePaths, false);


This is how the ESRI examples show it working, but I get a null reference on mapDoc each time.  The MXD is loaded and I can get IMxDocument just fine.  I can't save that though, I need IMapDocument.

Any thoughts?
Reply
0 Kudos
4 Replies
KirkKuykendall
Regular Contributor
Did you try IApplication.SaveAsDocument ?
Reply
0 Kudos
by Anonymous User
Not applicable
Original User: jscheirer

Using the current ArcMap document as IMapDocument only works in ArcGIS 10.0. You will need to use a combination of IApplication and IApplication.Document (as IMxDocument) to accomplish this.
Reply
0 Kudos
by Anonymous User
Not applicable
Original User: abrown

Did you try IApplication.SaveAsDocument ?


Did not catch that one.  I will try it.  However, is there an easy way to get the path of the current MXD?
Reply
0 Kudos
KirkKuykendall
Regular Contributor
The last template in the templates collection ....
IApplications.Templates(IApplication.Templates.Count -1)
Reply
0 Kudos