Problem building a map using IMapDocument

01-02-2014 05:05 PM
New Contributor III
I've got an application I've built where the user can load it up after selecting a single line and it will pick up on datasets near said line (rasters, vectors etc.) I'm trying to build a simple export function where it saves a cut down sample of the data near the selected line (so rasters trimmed to fit the envelope of the line and feature classes only exporting data that intersects).

For the most part it works, but as part of my application I save an XML config file in the same location as the MXD file. When I export my data it copies the XML file to be near the new MXD I create. But when I load the MXD in the application templates are wrong so it doesn't know where the MXD really is. For example, in this case:

        Dim pTemplates As ITemplates = CType(m_app, IApplication).Templates
        Dim lTempCount As Long = pTemplates.Count

        strDocPath = pTemplates.Item(lTempCount - 1)

I should have strDocPath set to something like "c:\projects\ProjectName\Project.mxd". Instead it is set to "C:\Users\amills\AppData\Local\Temp\~DFADDB648B646D99A1.TMP" when I load the new MXD in. That looks like the kind of path I'd get if the map had not been saved to an MXD so I'm not sure why I'm seeing it. The code that generates the new MXD looks like this (I've cut out a lot of the layers being added for this sample):

            Dim outMap As IMapDocument = New MapDocument

            copyFC = outWS.CreateFeatureClass(CType(locationFC, IDataset).Name, CType(locationFC.Fields, IClone).Clone, pUID, Nothing, esriFeatureType.esriFTSimple, locationFC.ShapeFieldName, Nothing)
            pFCLoad = copyFC
            pFCLoad.LoadOnlyMode = True
            insertCursor = copyFC.Insert(True)
            copyFeature = copyFC.CreateFeatureBuffer
            For counter = 0 To selectedFeature.Fields.FieldCount - 1
                If selectedFeature.Fields.Field(counter).Editable AndAlso Not selectedFeature.Fields.Field(counter).Type = esriFieldType.esriFieldTypeGeometry Then
                    copyIDX = copyFC.FindField(selectedFeature.Fields.Field(counter).Name)
                    copyFeature.Value(copyIDX) = selectedFeature.Value(counter)
                End If
            copyFeature.Shape = selectedFeature.ShapeCopy

            insertCursor = Nothing
            pFCLoad.LoadOnlyMode = False
            addLayer = New FeatureLayer
            CType(addLayer, IFeatureLayer).FeatureClass = copyFC
            addLayer.Name = currentLayer.Name

            CType(outMap, IMapDocument).Save(True, True)

Any ideas please?
0 Kudos
0 Replies