we have an ArcGIS engine Application .NET in C#.
We have an function to change the layout/template.
Under ArcGIS 9.x it was working fine with mxt-Files.
After migrating to ArcGIS10.2.1 i changed the filter to load also mxd-Files because under 10.x you can only create mxd-"Templates".
But our Function is not working anymore.
The PageLayout is already drawn from the template but when the mapcontrol from the actual map is loaded into the IPageLayoutControl2 Object by ReplaceMaps, the functions runs into Nirvana and doesn't respond:
Any suggestions? I found nothing in the web.
Regards Christoph Römer
public override void OnClick()
if (m_hookHelper != null)
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Vorlage (*.mxd)|*.mxd|Vorlage (*.mxt)|*.mxt";
dlg.Multiselect = false;
dlg.Title = "Vorlage Öffnen";
if (dlg.ShowDialog() == DialogResult.OK)
sFilePath = dlg.FileName;
IMaps maps = new Maps();
maps.Add(MyMap); //MyMap is IMap
IMapDocument mapDoc = new MapDocumentClass();
//MyLayoutControl is IPageLayoutControl2
MyLayoutControl.PageLayout = mapDoc.PageLayout;
MyLayoutControl.PageLayout.ReplaceMaps(maps); //!!! Function doesn't respond, killed after 30 minutes !!!
IGraphicsContainer pGc = MyLayoutControl.ActiveView.GraphicsContainer;
IElement pElem = pGc.Next();
while (pElem != null)
if (pElem is IMapSurroundFrame)
pMapSF = pElem as IMapSurroundFrame;
if (pMapSF.MapSurround is IMapSurround)
pMS = pMapSF.MapSurround as IMapSurround;
if (pMS is ILegend)
pElem = pGc.Next();
if (m_hookHelper.ActiveView is IPageLayout)
MyLayoutControl.Refresh(esriViewDrawPhase.esriViewForeground, null, null);
MessageBox.Show("Die Vorlage konnte nicht geladen werden.","Vorlage Laden");
if (m_hookHelper.ActiveView is IMap)
I didn't solve the problem itself, but i got a workaround:
I realized that the function only ran into nirvana, when the IPageLayoutControl2 was ActiveView before.
If the IMapControl3 was ActiveView the function worked.
So when loading the mxd as template i switched the ActiveView to mapcontrol when it was pagelayoutcontrol before loading and back afterwards.