Select to view content in your preferred language

arcgis Map c# The process cannot access the file C:\Users.. because it is being used

1814
4
08-13-2012 06:47 AM
mustafaguner
Emerging Contributor
0  down vote  favorite


I have a problem in arcgis c#. I am using Arcgis axMapControl component and adding image to it but I can not delete image when wanted to delete from axMapControl component... I have get a exception such as " The process cannot access the file C:\Users.. because it is being used by another process " I need your help 🙂 and verryyy thankss for your helps 🙂

code

    public void Add_map()
     {
      IRasterLayer my_raster = new RasterLayer();
      my_raster.FromFile(path);
      AxMapControl1.AddLayer(my_raster);
    }
    //--------------------------------------------------
    public void Delete_map()
    {
    AxMapControl1.DeleteLayer(0);
    System.IO.File.delete(path);    //There is a Exception.... This problem...
   }
0 Kudos
4 Replies
mustafaguner
Emerging Contributor
can someone help me ..... very important 😞
0 Kudos
NeilClemmons
Honored Contributor
Before removing the layer from the map you should disconnect it from its data source by calling IDataLayer2.Disconnect.
0 Kudos
AlexanderGray
Honored Contributor
For files added to a map or a map control, AO keeps a lock on them even when they are removed from the map or map control.  You can try using disconnect or even call the com release on the raster but I have had more luck using IDataset.Delete and IDataset.CanDelete in those cases rather that calls to system.io.file.delete.
0 Kudos
mustafaguner
Emerging Contributor
Very thankss for your anwers 🙂 I will use dispose() or IDataset.Delete but dont this metods .... when I called this metods only becoming Equals and ReferenceEquals.   which is .dll file missing   what do should I for it.  also I added to ESRI.Arcgis.Carto and other .dll files.
0 Kudos