I have an IMap (include elements: text, line) and I want to store it into a field of a table in SQL, so I can load it again later. I used below codes, but I got an the error :
public class Test
{
IStream stream;
IMap myMap;
void Save()
{
IPersistStream perStream;
IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
stream = memoryStream as IStream;
perStream = (IPersistStream ) myMap ;
perStream.Save(stream, 0);
}
void Load()
{
IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
IPersistStream pstm = new MapClass();
pstm.Load(stream); **// throw error: Error HRESULT E_FAIL has been returned from a call to a COM component.**
myMap = (IMap)pstm;
}
}
Are there anyone can help ?
Thanks and regards,
I found out one way to save elements to an binary file and can load it again later as below codes:
void Save (AxPageLayoutControl pageControl)
{
IPersistStream perStream;
IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer;
graphicsContainer.Reset();
IElement pElement = graphicsContainer.Next();
while (pElement != null)
{
if (pElement is IMapFrame)
{
perStream = (IPersistStream)pElement ;
perStream.Save(memoryStream, 0);
memoryStream.SaveToFile("C:/image.bmp");
break;
}
pElement = graphicsContainer.Next();
}
}
void Load (AxPageLayoutControl pageControl)
{
IPersistStream perStream;
IMemoryBlobStream memoryStream = new MemoryBlobStreamClass();
IGraphicsContainer graphicsContainer = pageControl.ActiveView.GraphicsContainer;
graphicsContainer.Reset();
IElement pElement = graphicsContainer.Next();
while (pElement != null)
{
if (pElement is IMapFrame)
{
memoryStream.LoadFromFile("C:/image.bmp");
perStream = (IPersistStream)pElement;
perStream.Load(memoryStream);
IMapFrame frame = new MapFrameClass();
frame = (IMapFrame)perStream;
pElement = (IElement)frame;
break;
}
pElement = graphicsContainer.Next();
}
pageControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
But, I am finding a way to convert IPersistStream or IMemoryBlobStream to byte[] format, so I can store in SQL Server and load later. Are there anyone know this ?
Thanks and regards,