0

I am working with C# and ArcObjects. I have some functions that I need to run every time a map document is opened (.mxd, or any other type of map file as well). I have no idea of the code needed to accomplish this though.

An example would be that every time a map document is loaded up or opened, a message box could display that says: "Map document loaded successfully"

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user1898629
  • 329
  • 1
  • 4
  • 22
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Sep 28 '14 at 21:25
  • @JohnSaunders Sorry about that. Thanks for the edits. – user1898629 Sep 28 '14 at 21:33

1 Answers1

0

You need to create an extension to do this, and add a handler for the ArcMap.Events.OpenDocument event - there's a good example in the API Docs that has everything you need:

public class LogExtension : ESRI.ArcGIS.Desktop.AddIns.Extension
  {
    public LogExtension()
    {
    }

    protected override void OnStartup()
    {
      ArcMap.Events.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(Events_OpenDocument);
    }

    void Events_OpenDocument()
    {
      System.Windows.Forms.MessageBox.Show("I opened a document.");
    }
}
Juffy
  • 1,220
  • 13
  • 22