How to repair a broken MXD map document

2751
0
05-28-2010 07:26 AM
EdWheeless
New Contributor
I've written an ArcGIS Engine 9.3.1 app. I've included an MXD file with relative paths to a file geodatabase. I'd like the user to have the liberty to install the file geodatabase anywhere he/she pleases (even on a remote server). I record the path to the file geodatabase during installation to the system registry. Since the relative paths in the MXD file may no longer be valid, I've added code to my program which attempts to repair the embedded relative paths within the MXD based on the registry entry pointing to the actual location of the file geodatabase. Here's the start of my code:

void CMyMapClass::RepairBrokenDocumentPaths(IMapDocument* ipMapDocument)
{
[INDENT] long nCount;
ipMapDocument->get_MapCount(&nCount);

for (long i = 0; i < nCount; i++) {
[INDENT] IMapPtr ipMap;
ipMapDocument->get_Map(i, &ipMap);
RepairBrokenMapPaths(ipMap);[/INDENT] }[/INDENT]}

When I attempt to get Map 0, the program bombs. When I attempt to open the same MXD in ArcMap, I get the error message:

Opening the selected ArcMap document failed.

An unexpected error occurred while loading the map document.
Last Component: {7EE9C496-D123-11D0-8383-080009B996CC}

It may reference an extension that is not currently installed or one that failed to load.

The following extensions were present when the map was saved but are currently missing on your system:

-Toolbars
-HawthsTools3
-ESRI Animation
-Georeferencing
-Survey Analyst
-Business Analyst
-Military Analyst
-TabletPC Support
-Tracking Environment
-Data Interoperability
-Overposter Validation
-ESRI Metadata Extension
-ESRI Publisher Extension
-ESRI Route Hatching Extension

If I move the file geodatabase back to its original location relative to the MXD file, the document opens fine. Is there no way to programmatically open a MXD and repair its internal links?
0 Kudos
0 Replies