Can't load Mxd file in MapControl ?

525
2
Jump to solution
03-24-2013 05:12 PM
TaiBui
by
Occasional Contributor II
Hi,

I used below codes to save IMap into byte[] (to store in my database), but I can't load it again, are there anyone know what's wrong ?

public byte[] SaveMap(AxPageLayoutControl pageLayOut) {     IGraphicsContainer graphicsContainer = pageLayOut.GraphicsContainer;     graphicsContainer.Reset();     IElement pElement = graphicsContainer.Next();     while (pElement != null)     {            if (pElement is IMapFrame)            {                IMapDocument mapDocument = new MapDocumentClass();                if (File.Exists(@"D:\test.mxd"))                          File.Delete (@"D:\test.mxd");                 mapDocument.New(@"D:\test.mxd");                mapDocument.ReplaceContents((IMxdContents)pageLayoutTo2_3.ActiveView.FocusMap);                mapDocument.Save(true, true);                 System.IO.FileStream objFileStream = new System.IO.FileStream(@"D:\test.mxd", FileMode.Open);                byte[] result = new byte[objFileStream.Length];                objFileStream.Read(result, 0, (int)objFileStream.Length);                 return result;             }             pElement = graphicsContainer.Next();       } }  public void LoadMap(AxPageLayoutControl pageLayOut, byte[] result) {     IGraphicsContainer graphicsContainer = pageLayoutTo2_3.GraphicsContainer;     graphicsContainer.Reset();     IElement pElement = graphicsContainer.Next();     while (pElement != null)     {            if (pElement is IMapFrame)            {                                System.IO.FileStream oFileStream = new System.IO.FileStream(@"D:\test.mxd", FileMode.Append);                oFileStream.Write(result, 0, result.Length);                 IMapControl2 map = new MapControlClass();                map.LoadMxFile(@"D:\test.mxd", Type.Missing, Type.Missing );                 IMapFrame frame = new MapFrameClass();                frame.Map = map.Map;                pElement = (IElement)frame;                 pageLayOut.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);                 return;             }             pElement = graphicsContainer.Next();       } }
0 Kudos
1 Solution

Accepted Solutions
TaiBui
by
Occasional Contributor II
Hi,

I found out the reason,

In Load function, I fogot a line:

pageLayout.Actiview.FocusMap = map.Map      


above the line
pageLayOut.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);


Kind regards,

View solution in original post

0 Kudos
2 Replies
oyleiste
Occasional Contributor
maybe because of this line:
oFileStream.Write(result, 0, result.Length);

Check if filestream reads file correctly or not
0 Kudos
TaiBui
by
Occasional Contributor II
Hi,

I found out the reason,

In Load function, I fogot a line:

pageLayout.Actiview.FocusMap = map.Map      


above the line
pageLayOut.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);


Kind regards,
0 Kudos