Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all Files and Folders from Google Drive V2 using .Net

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?

My code is below :

 FilesResource.ListRequest listRequest = service.Files.List();
 var files = listRequest.Execute();

for that I have define scope as

var Scopes = { DriveService.Scope.Drive };
like image 350
Srusti Thakkar Avatar asked Mar 06 '17 09:03

Srusti Thakkar


People also ask

Can I get a list of files in Google Drive?

Create a new Google Sheets spreadsheet or open an existing spreadsheet where you want the list saved. Here's a tip: You can quickly create a new Google Sheets spreadsheet using https://spreadsheet.new. Create a sheet in the spreadsheet called "Files". The list of files will be written to the sheet.

How do I view files in Google Drive as a list?

Google Drive allows you to view your documents as thumbnail images or in a text list. The icon is in the toolbar to the left of the AZ icon. To switch from tile view to list view the icon resembles the list view of lines of text.


1 Answers

files.list has an optional parameter called q and it's used for searching:

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.

like image 87
DaImTo Avatar answered Oct 13 '22 05:10

DaImTo