Display list of files ( more than 1000 records ) from Google Drive using Google Drive API V3 in ASP.Net

Last Reply one year ago By aruna

Posted one year ago

Thru the below code, I can able to fetch 1000 records but I have totally 6500++ records in my drive. Searching google but unable to find out the correct solution.

As per reference, the description value of Parameter "pageSize" is "The maximum number of files to return per page. Acceptable values are 1 to 1000, inclusive. (Default: 100)".

So it means, we can get only 1000 records or if possible, then what's the way. Also, I dont understand about the Parameter "pageToken", wats the usage of 'nextPageToken' value in realtime.

Can anyone please help me out.

namespace gDrive
    class Program
        // If modifying these scopes, delete your previously saved credentials
        // at ~/.credentials/drive-dotnet-quickstart.json
        static string[] Scopes = { DriveService.Scope.DriveReadonly };
        static string ApplicationName = "Drive API .NET Quickstart";

        static void Main(string[] args)
            UserCredential credential;
            gDriveTableAdapter gDrive = new gDriveTableAdapter();

            using (var stream =
                new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                string credPath = System.Environment.GetFolderPath(
                credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new FileDataStore(credPath, true)).Result;
                //Console.WriteLine("Credential file saved to: " + credPath);

            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,

            // Define parameters of request.
            FilesResource.ListRequest listRequest = service.Files.List();
            listRequest.PageSize = 1000;
            listRequest.Fields = "nextPageToken, files(webViewLink, name)";

            // List files.
            IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
            if (files != null && files.Count > 0)
                foreach (var file in files)
                    gDrive.InsertQuery(file.Name, file.WebViewLink);
                Console.WriteLine(files.Count + " records fetched.");
                Console.WriteLine("No files found.");


Posted one year ago
Hi @aruna,
Please try the following

List and download files from Google Drive using Google Drive API in ASP.Net

It might help you.

Cheers Andrea.

Posted one year ago Modified on one year ago


Are you a human or a BOT?

Before replying or giving a link, read fully the question first. Did you understand what I m asking. Whenever I m asking a question, on the next minute, you are sending a irrelevant reply with useless link. Is this your hobby?

Your mentioned link is irrelevant and useless for my question. I m looking for the solution for pageSize/pageToken and not for Downloading a file.


Posted one year ago Modified on one year ago

Achieved thru Google Script. Thanks to mesgarpour (link)


var folderId = "Enter the Folder Id here";

// Main function 1: List all folders, & write into the current sheet.
function listFolders(){
  getFolderTree(folderId, false);

// Main function 2: List all files & folders, & write into the current sheet.
function listAll(){
  getFolderTree(folderId, true); 

// =================
// Get Folder Tree
function getFolderTree(folderId, listAll) {
  try {
    // If you want to search from the top (root) folder
    var parentFolder = DriveApp.getRootFolder();

    // If you want a tree of any sub folder
    //var parentFolder = DriveApp.getFolderById(folderId);

    // Initialise the sheet
    var file, data, sheet = SpreadsheetApp.getActiveSheet();
    sheet.appendRow(["Full Path", "Name", "Date", "URL", "Last Updated", "Description", "Size"]);

    // Get files and folders
    getChildFolders(parentFolder.getName(), parentFolder, data, sheet, listAll);

  } catch (e) {

// Get the list of files and folders and their metadata in recursive mode
function getChildFolders(parentName, parent, data, sheet, listAll) {
  var childFolders = parent.getFolders();

  // List folders inside the folder
  while (childFolders.hasNext()) {
    var childFolder = childFolders.next();
    // Logger.log("Folder Name: " + childFolder.getName());
    data = [ 
      parentName + "/" + childFolder.getName(),
    // Write

    // List files inside the folder
    var files = childFolder.getFiles();
    while (listAll & files.hasNext()) {
      var childFile = files.next();
      // Logger.log("File Name: " + childFile.getName());
      data = [ 
        parentName + "/" + childFolder.getName() + "/" + childFile.getName(),
      // Write

    // Recursive call of the subfolder
    getChildFolders(parentName + "/" + childFolder.getName(), childFolder, data, sheet, listAll);  


I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html