使用.Net列出Google Drive V2中的所有文件和文件夹 [英] List all Files and Folders from Google Drive V2 using .Net
问题描述
我正在使用Google API .Net客户端库在.Net中使用Google Drive API创建应用程序.
I am creating an application using Google Drive API in .Net using the Google API .Net client library.
在该列表请求中,从根文件夹以及子文件夹和共享文件中获取所有文件.我不想全部列出.我想要仅在根文件夹中可用的文件列表,而不在子文件夹中可用.怎么可能?
In that list request get all files from root folder as well as from child folders and shared files. I don't want to list them all. I want list of files which are available in root folders only, not from sub folders. Hows that possible?
我的代码如下:
FilesResource.ListRequest listRequest = service.Files.List();
var files = listRequest.Execute();
为此,我将范围定义为
var Scopes = { DriveService.Scope.Drive };
推荐答案
文件. list 有一个可选的parpamter,称为q,用于搜索
files.list has an optional parpamter called q its used for searching
q字符串用于搜索文件的查询字符串.请参见搜索 文件以获取有关支持的字段和操作的更多信息.
q string Query string for searching files. See Searching for files for more information about supported fields and operations.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.Q = "'root' in parents";
var files = listRequest.Execute();
将只列出根目录中的子项,而没有子项.我建议您在搜索过程中查看文档,了解如何使用它
Would just list things within the root directory with out the children. I suggest you check the documentation on search it goes though how to use it.
这篇关于使用.Net列出Google Drive V2中的所有文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!