Hi Rick,
Now i am able to create the diagram using the code. Thanks for the help....
I am facing another problem. When trying to display the diagram on adf map, most of the time diagram not displaying properly.
public void showDiagramUsingDiagramLayer(String diagramName, ESRI.ArcGIS.ADF.Web.UI.WebControls.Map SLDMap1)
{
IServerContext pServerContext = null;
ISchematicWorkspace pSchWorkspace = null;
ISchematicWorkspaceFactory pSchWorkspaceFac = null;
ISchematicDataset pSchematicDataset = null;
ISchematicDiagram finalSchemDiagram = null;
ISchematicDiagramContainer diagcontainer = null;
IEnumSchematicDiagram pEnumScheDiag = null;
IEnumSchematicFolder pEnumScheFolder = null;
ISchematicFolderContainer pSchematicFolderContainer = null;
ISchematicLayer pSchLayer = null;
ESRI.ArcGIS.Carto.ILayer pLayer = null;
#region Schematic Function
try
{
if (!SLDMap1.MapResourceManagerInstance.Initialized)
SLDMap1.MapResourceManagerInstance.Initialize();
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal gisresource = null;
gisresource = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)(SLDMap1.MapResourceManagerInstance.GetResource(0));
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.ServerContextInfo servCtxInfo = gisresource.ServerContextInfo;
pServerContext = servCtxInfo.ServerContext;
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality gisFunctionality = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)SLDMap1.GetFunctionality(0);
string errorMsg = "";
ESRI.ArcGIS.Carto.IMapServer mapServer = pServerContext.ServerObject as ESRI.ArcGIS.Carto.IMapServer;
ESRI.ArcGIS.Carto.IMapServerObjects mapServerObjects = (ESRI.ArcGIS.Carto.IMapServerObjects)mapServer;
ESRI.ArcGIS.Carto.IMap pMap = mapServerObjects.get_Map(mapServer.DefaultMapName);
ESRI.ArcGIS.Geodatabase.IWorkspace pWorkSpace = getWrkSpace(SLDMap1,gisresource, false); //fLayer.FeatureClass.FeatureDataset.Workspace;
pSchWorkspaceFac = pServerContext.CreateObject("esriSchematic.SchematicWorkspaceFactory") as ISchematicWorkspaceFactory;
pSchWorkspace = pSchWorkspaceFac.Open(pWorkSpace);
pSchematicDataset = pSchWorkspace.get_SchematicDatasetByName("RAPDRP.NewSchematicDataset");
diagcontainer = (ISchematicDiagramContainer)pSchematicDataset;
pEnumScheDiag = diagcontainer.SchematicDiagrams;
pSchLayer = pServerContext.CreateObject("esriSchematic.SchematicLayer") as ISchematicLayer;
for (int i = 0; i < diagcontainer.SchematicDiagrams.Count; i++)
{
finalSchemDiagram = pEnumScheDiag.Next();
if (finalSchemDiagram != null)
{
if (finalSchemDiagram.Name == diagramName)
{
pSchLayer.SchematicDiagram = finalSchemDiagram;
pLayer = (ESRI.ArcGIS.Carto.ILayer)pSchLayer;
break;
}
}
}
if (pLayer == null)
{
//Checking if diagram exist in folder.
pSchematicFolderContainer = pSchematicDataset as ISchematicFolderContainer;
pEnumScheFolder = pSchematicFolderContainer.SchematicFolders;
ISchematicFolder pSF = pEnumScheFolder.Next();
Boolean canExist = false;
while (pSF != null)
{
diagcontainer = (ISchematicDiagramContainer)pSF;
pEnumScheDiag = diagcontainer.SchematicDiagrams;
finalSchemDiagram = pEnumScheDiag.Next();
while (finalSchemDiagram != null)
{
if (finalSchemDiagram.Name == diagramName)
{
pSchLayer.SchematicDiagram = finalSchemDiagram;
pLayer = (ESRI.ArcGIS.Carto.ILayer)pSchLayer;
canExist = true;
break;
}
finalSchemDiagram = pEnumScheDiag.Next();
}
if (canExist) break;
pSF = pEnumScheFolder.Next();
}
}
if (pLayer != null)
{
pLayer.Name = diagramName;
pLayer.Visible = true;
//Delete already exist layer
if (pMap.LayerCount > 0)
{
deleteAllLayers(pMap);
}
//Add layer
pMap.AddLayer(pLayer);
//pMap.MoveLayer(pLayer, 1);
//(basically here making the layer visibility on)
MapFunctions(gisFunctionality);
pMap.AreaOfInterest = pLayer.AreaOfInterest;
mapServerObjects.RefreshServerObjects();
IEnvelope env = pServerContext.CreateObject("esriGeometry.Envelope") as IEnvelope;
env = (IEnvelope)pLayer.AreaOfInterest;
ESRI.ArcGIS.ADF.Web.Geometry.Envelope pEnvelope = ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.Converter.FromIEnvelope(env);
SLDMap1.Page.Session["DiagramFullExtent"] = pEnvelope;
SLDMap1.Extent = pEnvelope;
SLDMap1.Refresh();
SLDMap1.RefreshResource(SLDMap1.MapResourceManagerInstance.ResourceItems[0].Name);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (pServerContext != null)
pServerContext.ReleaseContext();
}
-----------------------------------------------------------------------------------------------
public void MapFunctions(ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality gisFunctionality)
{
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality pMapFunctionality = gisFunctionality;
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal mapResourceLocal = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)pMapFunctionality.Resource;
System.Collections.Generic.Dictionary<string, bool> visibleLayers = new System.Collections.Generic.Dictionary<string, bool>();
foreach (ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription layerDescription in mapResourceLocal.MapDescription.LayerDescriptions)
{
if (!(layerDescription.LayerID == 0))
{
visibleLayers.Add(layerDescription.LayerID.ToString(), true);
}
else
{
visibleLayers.Add(layerDescription.LayerID.ToString(), true);
}
}
// Register changes to server object - dynamic layer added.
mapResourceLocal.RefreshServerObjects();
// Reset the visibility of the layers in the resource's map description to what it was before updating the map service.
foreach (System.Collections.Generic.KeyValuePair<string, bool> layerVisiblePair in visibleLayers)
{
if (!(layerVisiblePair.Key.Contains("0")))
{
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality.UpdateVisibleLayer(
mapResourceLocal.MapDescription, layerVisiblePair.Key, layerVisiblePair.Value);
}
else
{
ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality.UpdateVisibleLayer(
mapResourceLocal.MapDescription, layerVisiblePair.Key, false);
}
}
}
Thanks
Sanjeev Kumar Sinha