I am working on a standalone application (C# VS 2010 arcGIS Engine 10) continuously running on a single computer. (this application should never stop).
part of it is a simple Map Document manager with MapControl+TOCControl : so user should be able to open MXD document, change few things like layer symbology, transparency, map name, and Save the map.
My map document and data files has to be stored this way : 1 folder for each Map Document containing 1 MXD file and all associated data files (vector data).
So each time the user open a map document (IMapDocument.Open), lock files are created, and as the application never stop, these lock files are not (never) removed, even if the user close the map and open another one. (or maybe I do something wrong there in my code).
My issue is that the user should be able to Delete a Map according this process : delete the folder containing the map document and all content : the mxd file and all data files (like shapefile). But once the map document has been opened, there are always lock files there and full delete of my folder is not possible.
Shapefile, file geodatabase and personal geodatabase generate LOCK files, so what kind of data format could I use ?
the important point is that my application does not allow data editing, I am only developing functionnalities for map configuration (symbols, zoom scale) and drawing temporary geometry in graphic layers... so I really don't need these LOCK files. I just need to use my vector data as basemap !
So I guess, I definitly need a read-only data format...
I've tried base map layer which is not working because it's a group layer still loading data such as shapefile of feature class
I've tried SDC data which is working fine, but i don't think I can generate my own SDC files with ArcGIS Desktop (is it possible ?)
any solution ?
IMapControl3 m_mapControl3 = (IMapControl3)axMapControl.Object; m_mapControl3.LoadMxFile(myFileName, string.Empty);
thanks for the tips, I would try to remove layers first to see if lock files are deleted (and post the result asap)
however, i am wondering how to close properly a map previoulsy opened on my MapControl by following code :IMapControl3 m_mapControl3 = (IMapControl3)axMapControl.Object; m_mapControl3.LoadMxFile(myFileName, string.Empty);
I don't see an "unloadMxFile" ! and when I use LoadMxFile to open another Map Document, the previous one still have lock files...
How can i close properly with IMapDocument::Close in my case ?
// private members private IMapDocument m_mapDoc; private IMap m_map; ... // Function Open a Map : if (axMapControl.CheckMxFile(mxdFileName)) { // If a map was already opened if (m_mapDoc != null) { // Close the map m_mapDoc.Close(); Marshal.ReleaseComObject(m_map); Marshal.ReleaseComObject(m_mapDoc); } else { m_mapDoc = new MapDocumentClass(); } m_mapDoc.Open(mxdFileName); m_map = m_mapDoc.get_Map(0); axMapControl.Map = m_map; } ... // Function Close a Map : if (m_mapDoc != null) { // Close the map (and stop displaying the map on MapControl) m_mapDoc.Close(); Marshal.ReleaseComObject(m_map); Marshal.ReleaseComObject(m_mapDoc); }
string _myFolder = @"D:\AllMyMaps\Map1"; //for example if (Directory.Exists(_myFolder) == true) { string _mxdFileName = @"D:\AllMyMaps\Map1\Map1.mxd"; // for example if (File.Exists(_mxdFileName ) == true) { _mapDoc.Open(_mxdFileName ); IMap _map = _mapDoc.get_Map(0); // I get only 1 map with only 1 shapefile ILayer _layer = _map.get_Layer(0); FeatureLayer _featureLayer = new FeatureLayerClass(); _featureLayer = (FeatureLayer)_layer; IDataLayer2 _datalayer2 = (IDataLayer2)_featureLayer; _datalayer2.Disconnect(); _map.DeleteLayer(_layer); _mapDoc.Save(true, false); Marshal.ReleaseComObject(_datalayer2); Marshal.ReleaseComObject(_featureLayer); Marshal.ReleaseComObject(_map); _mapDoc.Close(); Marshal.ReleaseComObject(_mapDoc); } // Delete the folder by System.IO Directory.Delete(myFolder, true); }
if (Directory.Exists(repertoire) == true) { string _cheminFichierMXD = @"D:\myMaps\MyMap1\MyMap1.mxd"; if (File.Exists(_cheminFichierMXD) == true) { _mapDoc.Open(_cheminFichierMXD); IMap _map = null; // initialize object to "null" in order to be able to comrelease at the end ILayer _layer = null; FeatureLayer _featureLayer = null; IDataset _dataset = null; int _mapsCount = _mapDoc.MapCount; for (int ixMap = 0; ixMap < _mapsCount; ixMap++) { _map = _mapDoc.get_Map(ixMap); int _layersCount = _map.LayerCount; for (int ixLayer = (_layersCount-1); ixLayer > -1; ixLayer--) { _layer = _map.get_Layer(ixLayer); _featureLayer = _layer as FeatureLayer; if (_featureLayer != null) { if (_featureLayer.FeatureClass != null) { _dataset = _featureLayer.FeatureClass as IDataset; if (_dataset != null) { if (_dataset.CanDelete()) { _dataset.Delete(); // shapefiles are deleted there } } } } _map.DeleteLayer(_layer); } } _mapDoc.Save(true, false); _mapDoc.Close(); Marshal.FinalReleaseComObject(_dataset); Marshal.FinalReleaseComObject(_featureLayer); Marshal.FinalReleaseComObject(_map); Marshal.FinalReleaseComObject(_mapDoc); // lock files disappeared at this point } // Suppression complète du répertoire Directory.Delete(repertoire, true); // work without error, as there is no lock files ! }