My program's purpose is to go through every .mxd file in a given directory, delete their old and broken annotation layers, and add in new ones for specific feature classes. The old annotation sources in the geodatabase are combined into a single annotation file per feature class type. (So instead of having bAnno1, bAnno2...it would be bAnnos. This saves space and lessens ArcGIS editing time.)
My problem is the creation of the new annotation layers. My original code was along these lines (creating the first five variables only once outside loops):
IMapDocument mapdoc = new MapDocumentClass();
IWorkspaceFactory iwf = new FileGDBWorkspaceFactoryClass();
IFeatureWorkspace workspace = (IFeatureWorkspace)iwf.OpenFromFile(path, 0);
IFeatureDataset dataset = workspace.OpenFeatureDataset(datasetName);
IFeatureClassContainer container = (IFeatureClassContainer)dataset;
// Here is where it enters the loop for .mxd files
IMap pMap = mapdoc.get_Map(0);
// Here it removes old annotation layers first
IFeatureLayer newlayer = new FeatureLayerClass();
newlayer.DataSourceType = "File Geodatabase Feature Class";
newlayer.Name = "Anno Name";
newlayer.FeatureClass = container.get_ClassByName(annoName);
pMap.AddLayer((ILayer)newlayer);
The added layers match the original annotation layers in everything but the Symbology. In other words, ArcGIS sees these added files as a Feature Class of polygons instead of an Annotation Class with words. Looking at my code, I can see why.
So how do I make it exclusively an annotation layer? Or how do I make an annotation layer using an existing source in a dataset in the geodatabase?
Failed attempts include using:
AnnotationFeatureClass tempLayer = new AnnotationFeatureClass();
IAnnoClass newlayer = (IAnnoClass)tempLayer;
and
IAnnotationLayerFactory annofactory = new FDOGraphicsLayerFactoryClass();
IAnnotationLayer annoLayer = annofactory.CreateAnnotationLayer(...);
One of the above methods might actually be the answer; I could be incorrectly doing things.
Additional details: using ArcGIS 10, working with .mxd files made from ArcGIS 9.3 and 10.