Jan 5 at 9:06 PM
Hello Happy New Year to all
I need to do something I have not done.

I have a code that appears when you read a shape of my hard drive does not close any object and stays as pointing to the file when another method attempts to access the same resource throws me the following error.

"The process can not access the file 'SJ01000315-STONE FUEGO.shp' because it is being used by another process."

can anyone help me how to close it.

This is the code:
            SharpMap.Data.FeatureDataSet DatSet = new FeatureDataSet();
            SharpMap.Data.FeatureDataTable Datable = new FeatureDataTable();
            SharpMap.Layers.VectorLayer Vector = new SharpMap.Layers.VectorLayer("shp");
            CargaProvider = ruta + "\\DesShape" + "\\" + shape;
            SharpMap.Data.Providers.ShapeFile ArchivoShp = null;
            ArchivoShp = new SharpMap.Data.Providers.ShapeFile(CargaProvider, true);                              
            ArchivoShp.Encoding = Encoding.GetEncoding(1252);
            var Geometria = ArchivoShp.ShapeType;//Muestra la geometria poligono padre
            SP.mTipoGeometria = ArchivoShp.ShapeType.ToString();
            var Proyeccion = ArchivoShp.CoordinateSystem;
            if (Proyeccion != null)
            { SP.mTipoProyeccion = ArchivoShp.CoordinateSystem.ToString(); }
            if (Geometria.ToString() == "Polygon" || Geometria.ToString() == "POLYGON")
                var NumRegistros = ArchivoShp.GetFeatureCount();
                for (uint i = 0; i < NumRegistros; i++)//recorrer registro x registro
                    var RegistroP = ArchivoShp.GetFeature(i); 
                    var CoordenadasP = RegistroP.Geometry;
                    SP.mCentroideShp = RegistroP.Geometry.Centroid.ToString();
                    SP.mAreaShp = RegistroP.Geometry.Area.ToString();
                    SP.mMaxExtShp = RegistroP.Geometry.EnvelopeInternal.MaxExtent.ToString();
                    SP.mMinExtShp = RegistroP.Geometry.EnvelopeInternal.MinExtent.ToString();
                    SP.mMaxXShp = RegistroP.Geometry.EnvelopeInternal.MaxX.ToString();
                    SP.mMinExtShp = RegistroP.Geometry.EnvelopeInternal.MinX.ToString();
                    SP.mMaxYShp = RegistroP.Geometry.EnvelopeInternal.MaxY.ToString();
                    SP.mMinYShp = RegistroP.Geometry.EnvelopeInternal.MinY.ToString();
                    SP.mPerimetroShp = CoordenadasP.Length.ToString();
                    numcordenadasP = CoordenadasP.NumPoints;
                    verticesPadre = new string[numcordenadasP];
                    numcordenadasH = CoordenadasP.Envelope.NumPoints;
                    var Areah = CoordenadasP.Envelope.Area;
                    var Centroideh = CoordenadasP.Envelope.Centroid;
                    verticesHijos = new string[numcordenadasH];
                    poligonoHijo = "POLYGON ((";
                    for (int s = 0; s < numcordenadasH; s++)//

                    poligonoHijo += "))";
                    SP.mPolygonHijo = poligonoHijo;
                    poligonoPadre = "POLYGON ((";
                    for (int s = 0; s < numcordenadasP; s++)

                    poligonoPadre += "))";
                    SP.mPolygonPadre = poligonoPadre;
                   var CaposdeTupla = RegistroP.ItemArray;
                    string ID = CaposdeTupla[1].ToString();
                    SP.mAreaRegente = CaposdeTupla[2].ToString();
                    SP.mPerimetroRegente = CaposdeTupla[3].ToString();
                    SP.mUso = CaposdeTupla[4].ToString();
                    SP.mPlano = CaposdeTupla[5].ToString();
                    SP.mPresolicitud = CaposdeTupla[6].ToString();
                    SP.mTipoProyeccion = "EPSG5367";
                    DateTime localDate = DateTime.Today;
                    string fecha = localDate.Day.ToString();
                    fecha += localDate.Month.ToString();
                    fecha += localDate.Year.ToString();
                    SP.mLlaveRegistro = "Py" + fecha;

Jan 7 at 8:50 PM
Edited Jan 7 at 8:51 PM
Maybe it is my ignorance on spanish (?) but can you elaborate what this piece of code is supposed to do?
Jan 11 at 11:57 AM
This code reads the attributes of a shape file dbf
and others like projection, area, perimeter but I put the code there incomplete
Jan 13 at 12:29 PM
At which line do you get the exception? I'm wondering because there are several unit test that show that concurrent usage of shapefile provider should be possible.
Jan 14 at 12:31 PM
within the code shown here no problem,
the problem is that when these lines are executed:
CargaProvider var = @ "C: /temp.sanjose.shp"
SharpMap.Data.Providers.ShapeFile ArchivoShp = null;
             ArchivoShp = new SharpMap.Data.Providers.ShapeFile (CargaProvider, true);
within the repository SHP, SHX, DBF, PRJ to sanjose; shp.shp file but not how close it is generated and remains open.

if the file is still open to families when I try to read and modify it gives me an error that another application running sanjose.shp file; I like to be close once it finds used.

Here ArchivoShp.Open ();
Here ArchivoShp.Close ();

but apparently not close the communication between the SharpMap.Data.Providers.ShapeFile and physical file c: /temp/sanjose.shp

I do not know if I understand ....
Jan 14 at 1:07 PM
Since you instantiate the ArchivoShp in this method, try to dispose it when you no longer need it (Using block).
Are you using the same constructor and arguments at the second place you try to access the file?
Jan 20 at 1:25 PM
Edited Jan 20 at 1:29 PM
use it and so does not close,
continues the same problem
            CargaProvider = p_ruta + "\\" + "temporal\\descomprimidos" + "\\" + p_shape;
            SharpMap.Data.Providers.ShapeFile datos = null;
            using (datos = new SharpMap.Data.Providers.ShapeFile(CargaProvider, false)) 
              datos.Encoding = Encoding.GetEncoding(1252);
              SP.mTipoGeometria = datos.ShapeType.ToString();
              SP.mPlano  = datos.CoordinateSystem.ToString();
Jan 20 at 1:34 PM
Jan 20 at 2:42 PM
Jan 20 at 6:34 PM
Try opening the Shapefiles with the same constructor arguments. One time you use true, the other time false. Use true in both cases.