In below function I sent some rows' ID and it creates for me new shape file based on the IDs:
public static void SaveSomeRowsofLayerAsShapeFile(Collection<string> featureIDs, FeatureLayer ParentLayer, string DestinationFolder, string ShapeFileName)
{
try
{
ShapeFileName = ShapeFileName.ToLower().Replace(".shp", "") + ".shp";
string DestinationPath = DestinationFolder + ShapeFileName;
ParentLayer.Open();
Collection<FeatureSourceColumn> allColumns = ParentLayer.QueryTools.GetColumns();
Collection<ThinkGeo.MapSuite.Core.Feature> allFeatures = ParentLayer.QueryTools.GetFeaturesByIds(featureIDs, new string[0]);
ShapeFileType ParentShapeFileType = ((ShapeFileFeatureLayer)ParentLayer).GetShapeFileType();
ParentLayer.Close();
Collection<DbfColumn> dbfColumns = new Collection<DbfColumn>();
foreach (FeatureSourceColumn featureSourceColumn in allColumns)
{
DbfColumn dbfColumn = new DbfColumn(featureSourceColumn.ColumnName, DbfColumnType.String, 50, 0);
dbfColumns.Add(dbfColumn);
}
ShapeFileFeatureLayer.CreateShapeFile(ParentShapeFileType, DestinationPath, dbfColumns, System.Text.Encoding.UTF8, OverwriteMode.Overwrite);
ShapeFileFeatureLayer tmpShapeFileLayer = (new Basemap.DataAccess.DataProvider.ShapeFile()).Load(DestinationPath, ShapeFileReadWriteMode.ReadWrite);
tmpShapeFileLayer.Open();
tmpShapeFileLayer.EditTools.BeginTransaction();
foreach (ThinkGeo.MapSuite.Core.Feature feature in allFeatures) tmpShapeFileLayer.EditTools.Add(feature);
TransactionResult result = tmpShapeFileLayer.EditTools.CommitTransaction();
tmpShapeFileLayer.Close();
if (result.TotalFailureCount > 0)
{
throw new Exception(string.Format("{0} failed", result.TotalFailureCount));
}
}
catch
{ throw; }
}
it create a new shape file and I can open.
the Problem is that in the new shapefile the relevant DBF file is empty.