Beispiel #1
0
        private void ExportDatasetToXML(string fileGdbPath, string sourceFCName, string outputXmlFile)
        {
            // Open the source geodatabase and create a name object for it.
            IWorkspaceName sourceWorkspaceName = getWorkspaceName("esriDataSourcesGDB.FileGDBWorkspaceFactory", fileGdbPath);

            IFeatureClassName sourceFeatureClassName = getFeatureClassName(sourceWorkspaceName, sourceFCName);
            IName             sourceName             = (IName)sourceFeatureClassName;

            // Create a new names enumerator and add the feature dataset name.
            IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();

            enumNameEdit.Add(sourceName);
            IEnumName enumName = (IEnumName)enumNameEdit;

            // Create a GeoDBDataTransfer object and create a name mapping.
            IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
            IEnumNameMapping   enumNameMapping   = null;

            geoDBDataTransfer.GenerateNameMapping(enumName, sourceWorkspaceName as IName, out enumNameMapping);

            // Create an exporter and export the dataset with binary geometry, not compressed,
            // and including metadata.
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();

            gdbXmlExport.ExportDatasets(enumNameMapping, outputXmlFile, true, false, true);
        }
Beispiel #2
0
        public static void ExportToXml(IWorkspace sourceWorkspace, string targetPath,bool binaryGeometry,bool compressed,bool retriveMetadata)
        {
            // Open the source geodatabase and create a name object for it.
            IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
            //IWorkspace workspace = workspaceFactory.OpenFromFile(databaseName, 0);
            IDataset workspaceDataset = (IDataset)sourceWorkspace;
            IName workspaceName = workspaceDataset.FullName;

            // Retrieve the first feature dataset from the workspace.
            IEnumDatasetName enumDatasetName = sourceWorkspace.get_DatasetNames
              (esriDatasetType.esriDTFeatureDataset);
            enumDatasetName.Reset();
            IName featureDatasetName = (IName)enumDatasetName.Next();
            if (featureDatasetName == null)
            {
                throw new Exception(
                  "No feature datasets exist in the specified geodatabase.");
            }

            // Create a new names enumerator and add the feature dataset name.
            IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();
            enumNameEdit.Add(featureDatasetName);
            IEnumName enumName = (IEnumName)enumNameEdit;

            // Create a GeoDBDataTransfer object and create a name mapping.
            IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
            IEnumNameMapping enumNameMapping = null;
            geoDBDataTransfer.GenerateNameMapping(enumName, workspaceName, out enumNameMapping);

            // Create an exporter and export the dataset with binary geometry, not compressed,
            // and including metadata.
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();
            gdbXmlExport.ExportDatasets(enumNameMapping, targetPath, binaryGeometry, compressed, retriveMetadata);
        }
Beispiel #3
0
        } // getFCNames

        public void doWork()
        {
            Log.p("doWork started...");
            String sdeconnfname = mSdeConnFileName; // "c:\\t\\test.sde";
            String tabnames     = mTabName;         // "T.TAB1,T.TAB2";

            Log.p("Open the source gdb");
            IWorkspaceFactory wspFact = new SdeWorkspaceFactoryClass();
            IWorkspace        wsp     = wspFact.OpenFromFile(sdeconnfname, 0);

            Log.p("Get FC names");
            IEnumNameEdit edtNames = getFCNames(wsp, tabnames);
            IEnumName     names    = (IEnumName)edtNames;

            Log.p("Create a scratch workspace factory");
            IScratchWorkspaceFactory scrWspFact = new ScratchWorkspaceFactoryClass();
            IWorkspace scrWsp     = scrWspFact.CreateNewScratchWorkspace();
            IDataset   dset       = (IDataset)scrWsp;
            IName      scrWspName = dset.FullName;

            Log.p("Create a Transfer object and a name mapping");
            IGeoDBDataTransfer trans        = new GeoDBDataTransferClass();
            IEnumNameMapping   nameMaps     = null;
            Boolean            hasConflicts = trans.GenerateNameMapping(
                names, scrWspName, out nameMaps);

            if (hasConflicts)
            {
                throw new ArgumentException("Name mapping has conflicts.");
            }

            bool          expData    = mNeedData;
            string        fname      = mExpFileName;
            bool          getMeta    = mNeedMeta;
            bool          compressed = false;
            bool          binaryGeom = true;
            IGdbXmlExport exp        = new GdbExporterClass();

            if (expData == false)
            {
                Log.p(String.Format("Export schema (u need sdeexport for data); file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasetsSchema(nameMaps, fname, compressed, getMeta);
            }
            else
            {
                Log.p(String.Format("Export schema&data; file [{0}], metadata [{1}]",
                                    fname, getMeta));
                exp.ExportDatasets(nameMaps, fname, binaryGeom, compressed, getMeta);
            }

            Log.p("OK, xml writed.", "both");
        } // method doWork
        private static string ExportWorkspaceXml(IWorkspaceName workspaceName) {
            // Exclude FileSystemWorkspaces
            switch (workspaceName.Type) {
                case esriWorkspaceType.esriLocalDatabaseWorkspace:
                case esriWorkspaceType.esriRemoteDatabaseWorkspace:
                    break;
                case esriWorkspaceType.esriFileSystemWorkspace:
                default:
                    MessageBox.Show(
                        Resources.TEXT_DROPPED_OBJECT_NOT_GEODATABASE,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    return null;
            }

            // Get Workspace
            IName name = (IName)workspaceName;
            IWorkspace workspace = (IWorkspace)name.Open();

            // Create Temporary File
            string path = System.IO.Path.GetTempPath();
            string file = string.Format("{0}.{1}", Guid.NewGuid().ToString("N").ToUpper(), "xml");
            string outfile = System.IO.Path.Combine(path, file);
  
            //
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();
            try {
                gdbXmlExport.ExportWorkspaceSchema(workspace, outfile, false, true);
            }
            catch (COMException ex) {
                // Handle Exception
                ExceptionDialog.HandleException(ex);

                // Display Informative Error Message
                switch (ex.ErrorCode) {
                    case -2147220967: // 0x80040219
                        // Invalid network weight association.
                        // Connection to ESRI OLE DB provider is invalid.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_1A + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_1B,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147220735: // 0x80040301
                        // The dataset was not found.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_2,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147220655: // 0x80040351
                        // The table was not found
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_3,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147220473: // 0x80040407
                        // The feature class' default subtype code cannot be retrieved or is invalid.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_4,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147216558: // 0x80041352
                        // Unable to instantiate object class extension COM component.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_5,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147216100: // 0x8004151C
                        // You have insufficient permissions to access one or more datasets.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_6,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    case -2147216086: // 0x8004152A
                        // Specified attribute column doesn't exist.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_7,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                    default:
                        // Display a general error message.
                        MessageBox.Show(
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_8A + Environment.NewLine +
                            Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_8B,
                            Resources.TEXT_APPLICATION,
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.DefaultDesktopOnly);
                        break;
                }

                // Exit Method
                return null;
            }
            catch (Exception ex) {
                // Handle Exception
                ExceptionDialog.HandleException(ex);

                // Display a general error message.
                MessageBox.Show(
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_9A + Environment.NewLine +
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_9B,
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);

                // Exit Method
                return null;
            }

            // Clear Geodatabase Exporter
            gdbXmlExport = null;

            // Return pathname to Xml File
            return outfile;
        }
Beispiel #5
0
        public static void ExportDatabase(IWorkspace theWorkspace)
        {
            // Try and make sure the user understands what they're doing
            MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools");

            // Browse for a file, personal or SDE geodatabase
            IWorkspaceFactory wsFact          = null;
            IWorkspace        openedWorkspace = null;

            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject       openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database");

            if (openedObject == null)
            {
                return;
            }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
            case "Personal Geodatabase":
                wsFact     = new AccessWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "File Geodatabase":
                wsFact     = new FileGDBWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "Spatial Database Connection":
                wsFact = new SdeWorkspaceFactoryClass();
                IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                break;

            default:
                break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Okay, now export the current database to an XML doc
            string tempFilePath = System.IO.Path.GetTempFileName();

            tempFilePath += ".xml";

            IGdbXmlExport xmlExporter = new GdbExporterClass();

            xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false);

            // Import to the new database
            // Use the temp file to perform the import
            IGdbXmlImport    xmlImporter     = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;
            bool             conflictsFound  = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping);

            try
            {
                // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm)
                if (conflictsFound)
                {
                    IName workspaceName = ((IDataset)openedWorkspace).FullName;

                    // Iterate through each name mapping.
                    INameMapping nameMapping = null;
                    enumNameMapping.Reset();
                    while ((nameMapping = enumNameMapping.Next()) != null)
                    {
                        // Resolve the mapping's conflict (if there is one).
                        if (nameMapping.NameConflicts)
                        {
                            nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName);
                        }
                        // See if the mapping's children have conflicts.
                        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                        if (childEnumNameMapping != null)
                        {
                            childEnumNameMapping.Reset();
                            // Iterate through each child mapping.
                            INameMapping childNameMapping = null;
                            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                            {
                                if (childNameMapping.NameConflicts)
                                {
                                    childNameMapping.TargetName = nameMapping.GetSuggestedName
                                                                      (workspaceName);
                                }
                            }
                        }
                    }
                }

                // Perform the import
                xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath);
            }


            // Perhaps, strip the SysInfo table
        }
        private static string ExportWorkspaceXml(IWorkspaceName workspaceName)
        {
            // Exclude FileSystemWorkspaces
            switch (workspaceName.Type)
            {
            case esriWorkspaceType.esriLocalDatabaseWorkspace:
            case esriWorkspaceType.esriRemoteDatabaseWorkspace:
                break;

            case esriWorkspaceType.esriFileSystemWorkspace:
            default:
                MessageBox.Show(
                    Resources.TEXT_DROPPED_OBJECT_NOT_GEODATABASE,
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);
                return(null);
            }

            // Get Workspace
            IName      name      = (IName)workspaceName;
            IWorkspace workspace = (IWorkspace)name.Open();

            // Create Temporary File
            string path    = System.IO.Path.GetTempPath();
            string file    = string.Format("{0}.{1}", Guid.NewGuid().ToString("N").ToUpper(), "xml");
            string outfile = System.IO.Path.Combine(path, file);

            //
            IGdbXmlExport gdbXmlExport = new GdbExporterClass();

            try {
                gdbXmlExport.ExportWorkspaceSchema(workspace, outfile, false, true);
            }
            catch (COMException ex) {
                // Handle Exception
                ExceptionDialog.HandleException(ex);

                // Display Informative Error Message
                switch (ex.ErrorCode)
                {
                case -2147220967:     // 0x80040219
                    // Invalid network weight association.
                    // Connection to ESRI OLE DB provider is invalid.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_1A + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_1B,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147220735:     // 0x80040301
                    // The dataset was not found.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_2,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147220655:     // 0x80040351
                    // The table was not found
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_3,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147220473:     // 0x80040407
                    // The feature class' default subtype code cannot be retrieved or is invalid.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_4,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147216558:     // 0x80041352
                    // Unable to instantiate object class extension COM component.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_5,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147216100:     // 0x8004151C
                    // You have insufficient permissions to access one or more datasets.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_6,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                case -2147216086:     // 0x8004152A
                    // Specified attribute column doesn't exist.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_7,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;

                default:
                    // Display a general error message.
                    MessageBox.Show(
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_8A + Environment.NewLine +
                        Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_8B,
                        Resources.TEXT_APPLICATION,
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1,
                        MessageBoxOptions.DefaultDesktopOnly);
                    break;
                }

                // Exit Method
                return(null);
            }
            catch (Exception ex) {
                // Handle Exception
                ExceptionDialog.HandleException(ex);

                // Display a general error message.
                MessageBox.Show(
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED + Environment.NewLine +
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_9A + Environment.NewLine +
                    Resources.TEXT_GEODATABASE_SCHEMA_EXPORT_FAILED_9B,
                    Resources.TEXT_APPLICATION,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.DefaultDesktopOnly);

                // Exit Method
                return(null);
            }

            // Clear Geodatabase Exporter
            gdbXmlExport = null;

            // Return pathname to Xml File
            return(outfile);
        }
        public static void ExportDatabase(IWorkspace theWorkspace)
        {
            // Try and make sure the user understands what they're doing
            MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools");

            // Browse for a file, personal or SDE geodatabase
            IWorkspaceFactory wsFact = null;
            IWorkspace openedWorkspace = null;

            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database");
            if (openedObject == null) { return; }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
                case "Personal Geodatabase":
                    wsFact = new AccessWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "File Geodatabase":
                    wsFact = new FileGDBWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "Spatial Database Connection":
                    wsFact = new SdeWorkspaceFactoryClass();
                    IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                    pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                    break;
                default:
                    break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Okay, now export the current database to an XML doc
            string tempFilePath = System.IO.Path.GetTempFileName();
            tempFilePath += ".xml";

            IGdbXmlExport xmlExporter = new GdbExporterClass();
            xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false);

            // Import to the new database
            // Use the temp file to perform the import
            IGdbXmlImport xmlImporter = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;
            bool conflictsFound = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping);

            try
            {
                // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm)
                if (conflictsFound)
                {
                    IName workspaceName = ((IDataset)openedWorkspace).FullName;

                    // Iterate through each name mapping.
                    INameMapping nameMapping = null;
                    enumNameMapping.Reset();
                    while ((nameMapping = enumNameMapping.Next()) != null)
                    {
                        // Resolve the mapping's conflict (if there is one).
                        if (nameMapping.NameConflicts)
                        {
                            nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName);
                        }
                        // See if the mapping's children have conflicts.
                        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                        if (childEnumNameMapping != null)
                        {
                            childEnumNameMapping.Reset();
                            // Iterate through each child mapping.
                            INameMapping childNameMapping = null;
                            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                            {
                                if (childNameMapping.NameConflicts)
                                {
                                    childNameMapping.TargetName = nameMapping.GetSuggestedName
                                        (workspaceName);
                                }
                            }
                        }
                    }
                }

                // Perform the import
                xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath);
            }

            // Perhaps, strip the SysInfo table
        }