I hate when I can't find things easily on the web. Things are soo buried on the ESRI website its ridiculous. So I am going to start posting simple solutions and complaints if I find any. So thank you ESRI for being so hard to code for.
Complaint Number 1 about ESRI's site - When giving examples or even Class Objects, you don't show the namespaces. That leaves us developers looking for where classes are buried in several different namespaces. This is a problem that needs to be fixed.
So on to the example:
using ESRI.ArcGIS.Geodatabase;
IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(location, 0);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(shapefilename);
Console.WriteLine("There are {0} features in the {1} feature class", featureClass.FeatureCount(new QueryFilterClass()), featureClass.AliasName);
Make Note that the variable location is does NOT include the file name.
For example: "C:\Users\Desktop\Newfolder" and NOT "C:\Users\Desktop\Newfolder\blah.shp"
Thats it!
Hope this will help someone down the road. It took me about an hour to find it on the ESRI website.
If you liked this post, please be sure to subscribe to my
RSS Feed.