How to unlock shape file, just created

5856
4
05-21-2012 09:46 PM
AnatoliiTerentiev
Occasional Contributor III
I create shape file as follows:
IFeatureClass featClass = featWorkspace.CreateFeatureClass(shpName, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");

And created shape file - is locked:
file_name.shp.comp_name.3840.3932.sr.lock
.
How I can unlock shape file just created?
0 Kudos
4 Replies
AnatoliiTerentiev
Occasional Contributor III
How I can remove Schema lock?
That is full cod of creating shape file (C# VS2010 arcgis engine 2010):
        public void createShpFile(string shpName, DataTable dataTable)                          
        {
            //++++++++++++++  Create a new Shapefile with given name +++++++++++++++++++++++++++
            //Get the factory
            ShapefileWorkspaceFactory factory = new ShapefileWorkspaceFactory();

            //Create a workspace
            IWorkspaceName workspaceName = factory.Create(parentDirectory, catalogName, null, 0);
            

            IName name = workspaceName as IName;

            //QI to IFeatureWorkspace
            IFeatureWorkspace featWorkspace = (IFeatureWorkspace)name.Open();

            // Create a Fields collection to describe the fields of the new feature class.
            IFields fields = new Fields();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            // Add an "OBJECTID" field (feature classes must have this!)
            IField oidField = new Field();
            IFieldEdit oidFieldEdit = oidField as IFieldEdit;
            oidFieldEdit.Name_2 = "OBJECTID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            // Create a geometry definition object describing the geometries


            ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();

            IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            IProjectedCoordinateSystem pcs = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_Pulkovo1942GK_6);
            IGeometryDef geometryDef = new GeometryDef();
            IGeometryDefEdit geomDefEdit = geometryDef as IGeometryDefEdit;
            geomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            geomDefEdit.SpatialReference_2 = pcs;

            IField shpField = new Field();
            IFieldEdit shpFieldEdit = shpField as IFieldEdit;
            shpFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            shpFieldEdit.Name_2 = "Shape";
            shpFieldEdit.GeometryDef_2 = geomDefEdit;
            fieldsEdit.AddField(shpField);

            esriFieldType fieldType;
            int fieldLength;
            int i = 0;

            foreach (DataColumn col in dataTable.Columns)
            {
                IField aField = new Field();
                IFieldEdit aFieldEdit = aField as IFieldEdit;
                getFieldType(col, out fieldType, out fieldLength);
                aFieldEdit.Type_2 = fieldType;//esriFieldType.esriFieldTypeString
                string colName = col.ColumnName;
                if (colName.ToLower() == "пло�?ад�?_нелесной_зон�?")
                    colName = "�?ло�?ад�?Нелесной�?он�?";
                else if (colName == "код_пожа�?а_сзбаол")
                    continue;// colName = "код�?ожа�?азбаол";
                else if (colName == "код_�?айона_сзбаол")
                    continue;//

                aFieldEdit.Name_2 = colName;
                aFieldEdit.Length_2 = fieldLength;
                fieldsEdit.AddField(aField);
                i++;
            }
            //Create FeatureClass
            IFeatureClass featClass = featWorkspace.CreateFeatureClass(shpName, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
           

        }
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
How I can remove Schema lock?
That is full cod of creating shape file (C# VS2010 arcgis engine 2010):
        public void createShpFile(string shpName, DataTable dataTable)                          
        {
            //++++++++++++++  Create a new Shapefile with given name +++++++++++++++++++++++++++
            //Get the factory
            ShapefileWorkspaceFactory factory = new ShapefileWorkspaceFactory();

            //Create a workspace
            IWorkspaceName workspaceName = factory.Create(parentDirectory, catalogName, null, 0);
            

            IName name = workspaceName as IName;

            //QI to IFeatureWorkspace
            IFeatureWorkspace featWorkspace = (IFeatureWorkspace)name.Open();

            // Create a Fields collection to describe the fields of the new feature class.
            IFields fields = new Fields();
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            // Add an "OBJECTID" field (feature classes must have this!)
            IField oidField = new Field();
            IFieldEdit oidFieldEdit = oidField as IFieldEdit;
            oidFieldEdit.Name_2 = "OBJECTID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            // Create a geometry definition object describing the geometries


            ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();

            IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            IProjectedCoordinateSystem pcs = srFactory.CreateProjectedCoordinateSystem((int)esriSRProjCSType.esriSRProjCS_Pulkovo1942GK_6);
            IGeometryDef geometryDef = new GeometryDef();
            IGeometryDefEdit geomDefEdit = geometryDef as IGeometryDefEdit;
            geomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            geomDefEdit.SpatialReference_2 = pcs;

            IField shpField = new Field();
            IFieldEdit shpFieldEdit = shpField as IFieldEdit;
            shpFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            shpFieldEdit.Name_2 = "Shape";
            shpFieldEdit.GeometryDef_2 = geomDefEdit;
            fieldsEdit.AddField(shpField);

            esriFieldType fieldType;
            int fieldLength;
            int i = 0;

            foreach (DataColumn col in dataTable.Columns)
            {
                IField aField = new Field();
                IFieldEdit aFieldEdit = aField as IFieldEdit;
                getFieldType(col, out fieldType, out fieldLength);
                aFieldEdit.Type_2 = fieldType;//esriFieldType.esriFieldTypeString
                string colName = col.ColumnName;
                if (colName.ToLower() == "пло�?ад�?_нелесной_зон�?")
                    colName = "�?ло�?ад�?Нелесной�?он�?";
                else if (colName == "код_пожа�?а_сзбаол")
                    continue;// colName = "код�?ожа�?азбаол";
                else if (colName == "код_�?айона_сзбаол")
                    continue;//

                aFieldEdit.Name_2 = colName;
                aFieldEdit.Length_2 = fieldLength;
                fieldsEdit.AddField(aField);
                i++;
            }
            //Create FeatureClass
            IFeatureClass featClass = featWorkspace.CreateFeatureClass(shpName, fields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
           

        }



Release the resources....IFeatureClass, IFeatureWorkspace  variables....
e.g. marshal.ReleaseComobject(featClass);
HarshDesai1
New Contributor

I have same problem and i have also use this Marshal.ReleaseComObject(feturClass) but its not working.

0 Kudos
ThavitinaiduGulivindala
Occasional Contributor

Did you also release IWorkspaceName, iFeatureWorkspace?

Use interfaces instead of classes

use

IShapefileWorkspaceFactory factory = new ShapefileWorkspaceFactoryClass(); 

instead of

ShapefileWorkspaceFactory factory = new ShapefileWorkspaceFactory(); 

Alos, release IShapefileWorkspaceFactory

I am not sure, may work.