<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting path to MXD using IDocumentInfo2 in ArcObjects SDK Questions</title>
    <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99829#M2654</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a project that uses the ITemplates interface to get the mxd path.&amp;nbsp; If the document hasn't yet been saved it will return a string that ends in ".tmp", so maybe that's why some people use IDocumentInfo2.&amp;nbsp; Not sure what that interface would return if the doc hasn't been saved, though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&amp;nbsp; My advice would be to try one method and run it in debug mode with a couple of different scenarios.&amp;nbsp; If you don't get what you need then try the other one.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Jun 2011 22:12:22 GMT</pubDate>
    <dc:creator>KeithOlson</dc:creator>
    <dc:date>2011-06-21T22:12:22Z</dc:date>
    <item>
      <title>Getting path to MXD using IDocumentInfo2</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99828#M2653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I need to get the path to the currently open map document for a C# Add-In.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;While searching, I found several references that use essentially the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
public string GetActiveDocumentPath(IApplication application)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; // The active document is always the last template
&amp;nbsp;&amp;nbsp;&amp;nbsp; ITemplates templates = application.Templates;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return templates.get_Item(templates.Count - 1);
}&amp;nbsp; 

called with:
string mxdPath = GetActiveDocumentPath(ArcMap.Application);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then I found IDocumentInfo2.Path in the documentation, and it seems to work fine:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;
public string GetActiveDocumentPath(IMapDocument mapDocument)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp; IDocumentInfo2 docInfo = mapDocument as IDocumentInfo2;
&amp;nbsp;&amp;nbsp;&amp;nbsp; return docInfo.Path;
}

called with:
string mxdPath = GetActiveDocumentFolder(ArcMap.Document as IMapDocument);
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My question is if anyone knows of any reasons to use one versus the other.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jun 2011 21:17:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99828#M2653</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2011-06-21T21:17:01Z</dc:date>
    </item>
    <item>
      <title>Re: Getting path to MXD using IDocumentInfo2</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99829#M2654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a project that uses the ITemplates interface to get the mxd path.&amp;nbsp; If the document hasn't yet been saved it will return a string that ends in ".tmp", so maybe that's why some people use IDocumentInfo2.&amp;nbsp; Not sure what that interface would return if the doc hasn't been saved, though.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps.&amp;nbsp; My advice would be to try one method and run it in debug mode with a couple of different scenarios.&amp;nbsp; If you don't get what you need then try the other one.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Jun 2011 22:12:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99829#M2654</guid>
      <dc:creator>KeithOlson</dc:creator>
      <dc:date>2011-06-21T22:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting path to MXD using IDocumentInfo2</title>
      <link>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99830#M2655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Keith,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the heads-up about dealing with a new unsaved document. As it turns out, it IS an issue and I probably wouldn't have caught it until much later in testing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am streaming some data into the MXD in an overridden OnSave method in an Add-In Extension. It is some extended setup information for an Add-In that includes path information which must be re-written to use relative paths before saving in the MXD (and expanded to absolute after being read). That's why I need the path to the MXD.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;IDocumentInfo2.Folder was working fine in my initial tests. However, when saving&amp;nbsp; a new unsaved document, the Folder property is null (and the Path property is empty) -- even though OnSave occurs after the file save dialog. I suspect the properties are set AFTER the save completes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fortunately, The templates method of getting the path does work correctly in the first OnSave of a new document. So that's what I will be using.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Jun 2011 17:36:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcobjects-sdk-questions/getting-path-to-mxd-using-idocumentinfo2/m-p/99830#M2655</guid>
      <dc:creator>JeffreyHamblin</dc:creator>
      <dc:date>2011-06-22T17:36:53Z</dc:date>
    </item>
  </channel>
</rss>

