AnsweredAssumed Answered

Can't load Mxd file in MapControl ?

Question asked by taibc on Mar 24, 2013
Latest reply on Mar 27, 2013 by taibc
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();       } }

Outcomes