本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFS.FindOne方法的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFS.FindOne方法的具体用法?C# MongoGridFS.FindOne怎么用?C# MongoGridFS.FindOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.GridFS.MongoGridFS
的用法示例。
在下文中一共展示了MongoGridFS.FindOne方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: GetImageStream
private Stream GetImageStream(ImageData imageData, MongoGridFS mongoGridFS)
{
var file = mongoGridFS.FindOne(Query.EQ("_id", imageData.Id));
return file.OpenRead();
}
示例3: GetFileStream
public ReturnFileStream GetFileStream(String objectId)
{
var db = MongoDB.Driver.MongoDatabase.Create(_ConnectionString);
var gfs = new MongoGridFS(db);
var value = gfs.FindOne(objectId);
return new ReturnFileStream { Content = value.OpenRead(), ContentType = value.ContentType };
}
示例4: GetMeta
/// <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,
};
}