OpenRead() public method

Opens an existing GridFS file for reading.
public OpenRead ( string remoteFileName ) : MongoGridFSStream
remoteFileName string The remote file name.
return MongoGridFSStream
Example #1
0
        /// <summary>
        /// 获取流
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <returns></returns>
        public byte[] GetBytes(string remoteFile)
        {
            _logger.DebugFormat("Get Stream by Id {0}", remoteFile);

            try
            {
                MongoGridFS fs = new MongoGridFS(_context.DataBase);
                byte[] bytes;
                using (MongoGridFSStream gfs = fs.OpenRead(remoteFile))
                {

                    bytes = new Byte[gfs.Length];
                    gfs.Read(bytes, 0, bytes.Length);
                }
                return bytes;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
                throw;
            }
        }