當前位置: 首頁>>代碼示例>>C#>>正文


C# MongoGridFS.OpenWrite方法代碼示例

本文整理匯總了C#中MongoDB.Driver.GridFS.MongoGridFS.OpenWrite方法的典型用法代碼示例。如果您正苦於以下問題:C# MongoGridFS.OpenWrite方法的具體用法?C# MongoGridFS.OpenWrite怎麽用?C# MongoGridFS.OpenWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在MongoDB.Driver.GridFS.MongoGridFS的用法示例。


在下文中一共展示了MongoGridFS.OpenWrite方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AttachFile

        public void AttachFile(byte[] data, FileReference fileData, SCORMObject obj)
        {
            List<FileReference> files = new List<FileReference>();
            if (obj.Files != null)
            {
                files.AddRange(obj.Files);
            }

            var db = MongoDB.Driver.MongoDatabase.Create(_ConnectionString);
            var gfs = new MongoGridFS(db);
            var id = Guid.NewGuid().ToString();
            using (var file = gfs.OpenWrite(id))
            {
                file.Write(data, 0, data.Length);
                file.Flush();
            }
            var fileInfo = gfs.FindOne(id);
            gfs.SetContentType(fileInfo, fileData.ContentType);
            fileData.FileId = id;
            files.Add(fileData);
            obj.Files = files;
        }
開發者ID:wegrata,項目名稱:scorm-repository,代碼行數:22,代碼來源:SCORMObjectModel.cs

示例2: OpenStream

        public Stream OpenStream(string remoteFile, string mimetype)
        {
            _logger.DebugFormat("Open MongoDB By Stream, Id {0}.", remoteFile);

            Stream stream = null;

            try
            {
                MongoGridFSCreateOptions option = new MongoGridFSCreateOptions
                {
                    Id = remoteFile,
                    UploadDate = DateTime.Now,
                    ContentType = mimetype,
                };

                MongoGridFS fs = new MongoGridFS(_context.DataBase);
                stream = fs.OpenWrite(remoteFile, option);
                return stream;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                _logger.Error(ex.StackTrace);
                if (stream != null)
                {
                    stream.Close();
                }
                throw;
            }
        }
開發者ID:ideayapai,項目名稱:docviewer,代碼行數:30,代碼來源:MongoPolicy.cs


注:本文中的MongoDB.Driver.GridFS.MongoGridFS.OpenWrite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。