.NET 对实现IPersistStream接口的对象进行保存和读取

我们可以对实现IPersistStream接口的类的对象进行保存和读取,如Element,Map等等

以下为应用IPersistStream接口保存当前视图(Map)至文件读取文件并在当前视图展示的代码

 

            //保存当前视图至文件

            IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();

: yes;">            IObjectStream pObjectStream = new ObjectStreamClass();

            pObjectStream.Stream = pMemoryBlobStream;

 

            IPersistStream pPersistStream = (IPersistStream)m_map;

            pPersistStream.Save((IStream)pObjectStream, 0);

            pMemoryBlobStream.SaveToFile(@"e:\myfile.blb");

 

 

            //读取文件并在当前视图展现

            IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();

            pMemoryBlobStream.LoadFromFile(@"e:\myfile.blb");

            IObjectStream pObjectStream = new ObjectStreamClass();

            pObjectStream.Stream=pMemoryBlobStream;

            IPersistStream pPersistStream = (IPersistStream)m_map;

            pPersistStream.Load((IStream)pObjectStream);

 

            m_activeView.Refresh();

posted @ 2009-01-21 10:51  因是因非  阅读(1126)  评论(0编辑  收藏  举报