private void WireDocumentEvents()
{
// Named event handler
ArcMap.Events.OpenDocument += new IDocumentEvents_OpenDocumentEventHandler(Events_OpenDocument);
}
Call this event OnStartup(), so override it in the extension:
protected override void OnStartup()
{
// Wire the events
WireDocumentEvents();
}
Next stub out the Events_OpenDocument()
void Events_OpenDocument()
{
IMxDocument mxDoc = ArcMap.Document as IMxDocument;
IDocumentInfo2 docInfo = mxDoc as IDocumentInfo2;
docInfo.Comments += Environment.NewLine + "Opened On: " + DateTime.Now.ToString() + " by " + Environment.UserName;
if (docInfo.RelativePaths == false)
{
docInfo.RelativePaths = true;
}
}
Now if you look at the Map Documents properties in ArcMap you'll see something like:
"Opened On: 06/17/2011 3:02 AM by Bob1234"
An additional option would be to tack in a Save() to save the document right away so the information doesn't get lost if the user exits ArcMap.
private void Save()
{
ArcMap.Application.SaveDocument();
}