How to display absolute file path of .mxd document in a message box

864
4
08-15-2010 12:33 AM
MuzammilAK
New Contributor
Dear All,

I have a command (developed using .NET SDK) in ArcMap, on clicking it should display absolute file path of that .mxd document in a message box.

please help.

thank you.

regards
Muzammil
0 Kudos
4 Replies
vincentLahaye
New Contributor II
hi,

i don't know if it's what you are looking for, but IMapDocument.DocumentFileName give you the mxd path.

Vincent
0 Kudos
ModyBuchbinder
Esri Regular Contributor
0 Kudos
MuzammilAK
New Contributor
Dear Vincent,

I have tried your suggestion in following ways, but neither of it works. When tried to cast its always null.

1. Here mapDoc is always null.
IMapDocument mapDoc = ((IMxDocument)m_application.Document).FocusMap as IMapDocument;

2. Here also, mapDoc is always null.
IMapDocument mapDoc = m_application.Document as IMapDocument;

Please suggest some sample.

Thank you.

Regards
Muzammil
0 Kudos
AndrewMay
New Contributor
Try

ITemplates templates = application.Templates;
return templates.get_Item(templates.Count - 1);

The reason you are getting null values with the examples you've given is that you're trying to cast to IMapDocument but the objects implement the IDocument interface.
i.e. IDocument mapDoc = m_application.Document as IDocument;
should not be null (unless m_application is null or you've not loaded a document)
0 Kudos