本文整理汇总了C#中MongoDB.Driver.GridFS.MongoGridFS.Download方法的典型用法代码示例。如果您正苦于以下问题:C# MongoGridFS.Download方法的具体用法?C# MongoGridFS.Download怎么用?C# MongoGridFS.Download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDB.Driver.GridFS.MongoGridFS
的用法示例。
在下文中一共展示了MongoGridFS.Download方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Copy
/// <summary>
/// 下载文档到本地
/// </summary>
/// <param name="localfile"></param>
/// <param name="remoteFile"></param>
public void Copy(string localfile, string remoteFile)
{
_logger.DebugFormat("Copy {0} to {1}.", localfile, remoteFile);
try
{
MongoGridFS fs = new MongoGridFS(_context.DataBase);
fs.Download(localfile, remoteFile);
}
catch (Exception ex)
{
_logger.Error(ex.Message);
_logger.Error(ex.StackTrace);
throw;
}
}
示例2: Test2
static void Test2()
{
MongoServer ms = MongoServer.Create();
string _dbName = "docs";
MongoDatabase md = ms.GetDatabase(_dbName);
if (!md.CollectionExists(_dbName))
{
md.CreateCollection(_dbName);
} // End if (!md.CollectionExists(_dbName))
MongoCollection<Doc> _documents = md.GetCollection<Doc>(_dbName);
_documents.RemoveAll();
//add file to GridFS
MongoGridFS gfs = new MongoGridFS(md);
MongoGridFSFileInfo gfsi = gfs.Upload(@"c:\mongodb.rtf");
_documents.Insert(new Doc()
{
DocId = gfsi.Id.AsObjectId,
DocName = @"c:\foo.rtf"
}
);
foreach (Doc item in _documents.FindAll())
{
ObjectId _documentid = new ObjectId(item.DocId.ToString());
MongoGridFSFileInfo _fileInfo = md.GridFS.FindOne(Query.EQ("_id", _documentid));
gfs.Download(item.DocName, _fileInfo);
System.Console.WriteLine("Downloaded {0}", item.DocName);
System.Console.WriteLine("DocName {0} dowloaded", item.DocName);
} // Next item
//System.Console.ReadKey();
}