[GIS] How to save an ArcMap map document using VB.Net

arcmaparcobjectsvb.net

I am trying to save the map document that is currently open. How do I write the code? I have tried many suggestions that I found using Google searches, but nothing works. Currently I have:

Dim clickedDoc As IMapDocument = My.ArcMap.Application.Document
clickedDoc.Save(True, False)

which causes ArcMap to crash. I did get it to work with some other code, but it wouldn't actually save.

Also, this should be a background job. So no save dialog should come up.

Best Answer

You can just use the built in ArcMap Command Save, see example below.

    Dim pUID As New UID
    Dim pCmdItem As ICommandItem
    ' Use the GUID of the Save command
    pUID.Value = "{119591DB-0255-11D2-8D20-080009EE4E51}"
    ' or you can use the ProgID
    ' pUID.Value = "esriArcMapUI.MxFileMenuItem"
    pUID.SubType = 3
    pCmdItem = My.ArcMap.Application.Document.CommandBars.Find(pUID)
    pCmdItem.Execute()
Related Question