Reputation: 179
I have some queries regarding the google drive api. I am following the code from here( https://everyday-be-coding.blogspot.com/)
These are the issues are i am facing on with google drive api.Please help me out from these issues.
This is the code i am using to list the files
public static List<GoogleDriveFiles> GetDriveFiles()
{
DriveService service = GetService();
// Define parameters of request.
FilesResource.ListRequest FileListRequest = service.Files.List();
FileListRequest.Q = "mimeType = 'application/vnd.google-apps.folder'";
FileListRequest.Fields = "nextPageToken, files(id, name, size, version, trashed, createdTime)";
// List files.
IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files.Where(c => c.Trashed == false).ToList();
List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();
if (files != null && files.Count > 0)
{
foreach (var file in files)
{
GoogleDriveFiles File = new GoogleDriveFiles
{
Id = file.Id,
Name = file.Name,
Size = file.Size,
Version = file.Version,
CreatedTime = file.CreatedTime
};
FileList.Add(File);
}
}
return FileList;
}
Upvotes: 2
Views: 2900
Reputation: 2608
trashed = false
.‘folder id' in parents
.Hope this helps!
Upvotes: 3
Reputation: 117271
How to change default file list length(100) to full file list length from the google drive ?
files.list as a default max page size of 100 but you can increase that by sending the pageSize parameter you can set it between 100 - 1000.
After that you will need to use the NextPageToken. You are in luck in that we have a PageStreamer method for this in C#
var pageStreamer = new Google.Apis.Requests.PageStreamer<Google.Apis.Drive.v3.Data.File, FilesResource.ListRequest, Google.Apis.Drive.v3.Data.FileList, string>(
(req, token) => request.PageToken = token,
response => response.NextPageToken,
response => response.Files);
I have a tutorial on how to use it here https://www.daimto.com/list-all-files-on-google-drive/
How to avoid listing of file from the trash of google drive?
File.list has another paramater called the q paramater which will allow you to search for the files you are looking for search
so the following would ignore trashed files.
q = trashed = false
How to search and list out the content inside a specific folder with a folder name in the google drive?
To do this you will need to find the folder you are looking for the eastest way to do that would be to again use the q paramater and search for only folders with the name will help you find the folder you are looking for.
mimeType != 'application/vnd.google-apps.folder' and name = 'hello'
Once you have it save the file.id for that folder
mimeType != 'application/vnd.google-apps.folder' and name = 'hello'
Then you can make another request which will find all of the files in a parent folder
'the file id here' in parents
The best place to test your searches is in the try me on the documentation page here
My tutorials Search files on Google Drive with C#
Upvotes: 4