Exists() public method

Tests whether a GridFS file exists.
public Exists ( IMongoQuery query ) : bool
query IMongoQuery The GridFS file.
return bool
Example #1
0
        /// <summary>
        /// 获取元数据信息
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <returns></returns>
        public MetaInfo GetMeta(string remoteFile)
        {
            _logger.DebugFormat("GetMeta By Id{0}.", remoteFile);

            MongoGridFS fs = new MongoGridFS(_context.DataBase);
            if (!fs.Exists(remoteFile))
            {
                return null;
            }

            var info = fs.FindOne(remoteFile);
            return new MetaInfo
            {
                fileName = remoteFile,
                MD5 = info.MD5,
                MimeType = info.ContentType,
            };
        }
Example #2
0
        private void ImportFiles(MongoGridFS fs, IEnumerable<FileInfo> files, string root)
        {
            foreach (var file in files)
            {
                var name = file.FullName;
                if (!string.IsNullOrEmpty(root))
                {
                    name = name.Replace(root, string.Empty);
                }

                if(_unixStyle)
                    name = name.Replace('\\', '/');

                if (_winStyle)
                    name = name.Replace('/', '\\');

                Stream stream;

                if (fs.Exists(name))
                    stream = fs.Open(name, FileMode.Truncate, FileAccess.Write);
                else
                    stream = fs.Create(name);

                var fileStream = file.Open(FileMode.Open, FileAccess.Read);

                fileStream.CopyTo(stream);
                fileStream.Close();
                stream.Close();                
            }
        }
Example #3
0
        /// <summary>
        /// 判断文件是否存在
        /// </summary>
        /// <param name="remoteFile"></param>
        /// <returns></returns>
        public bool Exist(string remoteFile)
        {
            _logger.DebugFormat("Exist, Id {0}.", remoteFile);

            try
            {

                MongoGridFS fs = new MongoGridFS(_context.DataBase);
                return fs.Exists(remoteFile);

            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
                throw;
            }
        }