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 ?
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 ?
Code:
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();
}
}