That works Farid Cher, but another helpful tip is to use the autoLoad property in the Config.esriaddinx:
<Extensions>
<Extension id="Microsoft_OnSave_Extension1" class="Extension1" productName="OnSaveExt" showInExtensionDialog="true" autoLoad="true" />
</Extensions>
This may not be there by default but it is safe to add, it forces the tool to execute as ArcMap is initialized (before you even see it). Then in the code use the OnStartup to wire the OpenDocument event of ArcMap events:
//this goes in OnStartup
IDocumentEvents_Event eDocEvents = (IDocumentEvents_Event)ArcMap.Document;
eDocEvents.OpenDocument += new IDocumentEvents_OpenDocumentEventHandler(eDocEvents_OpenDocument);
void eDocEvents_OpenDocument()
{
// do your procedure in here
}
This is the C# translation of working VB code taken from an answer How to trigger a Python script from an ArcGIS Desktop "save" operation? that I have done previously.. I'm hoping nothing has got lost in the translation: the original was VB to be executed in python now translated to C#.
As you can see it's the same (essentially) as the answer by Farid Cher (+1 for that) except that it's not using an extension method, simply an ArcMap Addin, which doesn't need to be installed and can be handled the same as any Esri Addin.