_银子

提供更专注、更专心、更专业的服务
  首页  :: 联系 :: 订阅 订阅  :: 管理

利用ImemoryBlobStream做二进制流文件的读入写出

Posted on 2012-02-29 12:48  _银子  阅读(1276)  评论(0编辑  收藏  举报

最近利用ImemoryBlobStream做二进制流文件的读入写出,这个接口用起来很简单,还是直接贴代码直观。

public static bool FileToBlob(IFeature pFeature,string FileName)
        {
            try
            {
                IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
                pMemoryBlobStream.LoadFromFile(FileName);
               
                int Index = pFeature.Fields.FindField("BlobFile");

                pFeature.set_Value(Index, pMemoryBlobStream);
                pFeature.Store();
                return true;
            }
            catch
            {
                return false;
            }

        }

        public static bool BlobToFile(string FilePath, IFeature pFeature)
        {
            try
            {
                int Index = pFeature.Fields.FindField("BlobFile");
                if (pFeature.get_Value(Index) != null)
                {
                    IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();
                    pMemoryBlobStream = (IMemoryBlobStream)pFeature.get_Value(Index);
                    pMemoryBlobStream.SaveToFile(FilePath);
                    return true;
                }
                else return false;
            }
            catch
            {
                return false;
            }
        }