2

We have been successfully creating mxd files based on MapDocument, adding layers, setting spatial information and saving them. Our code has been working, literally, for years and has made the transition from 9.x to 10.x without trouble.

The other day we decided that we wanted to incorporate field based links that required us to use the HyperlinkBase attribute of the DocumentInfo class. We have tried the 5 or 6 most obvious ways to do that and have not been able to accomplish it. No matter what we insert into the IDocumentInfo or IDocumentInfo2 interface, it does not get saved with the mxd.

Furthermore, if you open an mxd that already has attributes (that you added with ArcMap, for example) twiddle them, and then save the mxd again ... all the attributes are cleared. This is intensely frustrating of course. Our code is of this form ...

IMapDocument mapDoc = null;

try
{
    mapDoc = ArcObjects.CartoUtil.OpenMxd(mxdPath, null);

    AddMapLayersToMxd( "our hidden, sanitized stuff goes here" );

    IDocumentInfo2 infoDoc = (IDocumentInfo2) mapDoc;
    infoDoc.HyperlinkBase = BlahBlah.ServerBaseUrl;

    mapDoc.Save(true, false);
    mapDoc.Close();
}
finally
{
    ComUtil.Release(mapDoc);
}

Where AddMapLayersToMxd() does just what it says. This works fine and the mxd has the layers and other things we add to it. Our desired DocumentInfo ... nowhere to be found.

If you crack the resulting mxd, you will find only the DocumentInfo added by the system ... paths, dates, RelativePaths, etc. None of the user-defined items.

1 Answer 1

2

From the IMapDocument help:

The IMapDocument interface provides properties and methods for reading map document files (*.mxd, *.mxt, *.pmf) and writing and saving changes to map document files (*.mxd). However, since it is not tied to the ArcMap application, application-specific functionality in the MapDocument will not be persisted.

The replies in this thread suggest using IApplication.SaveDocument or SaveAsDocument instead.

Also, how are you obtaining your IMapDocument reference?

3
  • Thanks for the help. I have seen that thread, but you do realize, though, that it is not clear to anyone but an ESRI guru why that paragraph should apply to the IDocumentInfo stream portion of the mxd. There is simply no documentation that I have found that says IDocumentInfo is "application-specific functionality." In fact one KB article support.esri.com/en/knowledgebase/techarticles/detail/40759 suggests that I can do precisely what I tried to do. I will try to save via the Application object and see what happens.
    – Ken Hawley
    Commented Jan 28, 2013 at 15:32
  • You are correct, I am only sharing what little information I found on the subject. I have not tested it. Documentation has always been a weak point with ESRI products.
    – blah238
    Commented Jan 28, 2013 at 16:09
  • By the way, the problem is that our code operates entirely without an IApplication now. It doesn't need one and hence we don't instantiate one. We would be unhappy to have to stand one up just to set these properties. We would be better off putting the entire URL into the layer and accept the redundancy. Grrr.
    – Ken Hawley
    Commented Jan 28, 2013 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.