-3

I am working with the Google drive API in C#. I have been looking at the file.list method.

I am trying to list the folders/files which are uploaded by me. As well as files/folders from specific folder based on folder name.

So far I have only been able to return a list of all my files.

var request = service.Files.List().Execute();
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
Hari
  • 7
  • Welcome to Stack Overflow. While there's a wealth of information here, this site is not a code writing service. To improve the quality of your Question, please show evidence of what research you have performed into this matter, including links to any pages that have been helpful or sound like they are likely to be related. Please show us any code you have tried and a description of the results you have received (including the full text of any error messages). [Look here for tips on writing a good question](http://stackoverflow.com/help/how-to-ask) – mmushtaq Feb 23 '18 at 12:20
  • Please check the [API documentation](https://developers.google.com/drive/v3/web/about-sdk) try something and come back if you have a more specific question. – Filburt Feb 23 '18 at 12:20
  • I have gone through api document. There I was getting files/folders based on parent id or is there any way to get id based on folder name? – Hari Feb 23 '18 at 12:24
  • 1
    i searched for 2 seconds, https://developers.google.com/drive/v3/web/quickstart/dotnet – TheGeneral Feb 23 '18 at 12:35
  • Please use google a bit more – TheGeneral Feb 23 '18 at 12:35
  • @Hari You need to show what you researched and tried - we'll have to assume you did not do any research and just want offload your homework. – Filburt Feb 23 '18 at 12:40
  • @MichaelRandall that quick start doesnt show anything about searching for files not sure it will help him. – Linda Lawton - DaImTo Feb 23 '18 at 13:12
  • 1
    @DaImTo on second look, you are right. – TheGeneral Feb 23 '18 at 13:17

1 Answers1

1

Files.list has a q parameter which allows you to search for files.

Sending a search like this

mimeType = 'application/vnd.google-apps.folder' and title = 'hello'

The following code should show you how to use the parameter code ripped from

public class FilesListOptionalParms
    {
        /// Comma-separated list of bodies of items (files/documents) to which the query applies. Supported bodies are 'user', 'domain', 'teamDrive' and 'allTeamDrives'. 'allTeamDrives' must be combined with 'user'; all other values must be used in isolation. Prefer 'user' or 'teamDrive' to 'allTeamDrives' for efficiency.
        public string Corpora { get; set; }  
        /// The source of files to list. Deprecated: use 'corpora' instead.
        public string Corpus { get; set; }  
        /// Whether Team Drive items should be included in results.
        public bool? IncludeTeamDriveItems { get; set; }  
        /// A comma-separated list of sort keys. Valid keys are 'createdTime', 'folder', 'modifiedByMeTime', 'modifiedTime', 'name', 'name_natural', 'quotaBytesUsed', 'recency', 'sharedWithMeTime', 'starred', and 'viewedByMeTime'. Each key sorts ascending by default, but may be reversed with the 'desc' modifier. Example usage: ?orderBy=folder,modifiedTime desc,name. Please note that there is a current limitation for users with approximately one million files in which the requested sort order is ignored.
        public string OrderBy { get; set; }  
        /// The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached.
        public int? PageSize { get; set; }  
        /// The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response.
        public string PageToken { get; set; }  
        /// A query for filtering the file results. See the "Search for Files" guide for supported syntax.
        public string Q { get; set; }  
        /// A comma-separated list of spaces to query within the corpus. Supported values are 'drive', 'appDataFolder' and 'photos'.
        public string Spaces { get; set; }  
        /// Whether the requesting application supports Team Drives.
        public bool? SupportsTeamDrives { get; set; }  
        /// ID of Team Drive to search.
        public string TeamDriveId { get; set; }  

    }

    /// <summary>
    /// Lists or searches files. 
    /// Documentation https://developers.google.com/drive/v3/reference/files/list
    /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
    /// </summary>
    /// <param name="service">Authenticated Drive service.</param>  
    /// <param name="optional">Optional paramaters.</param>
    /// <returns>FileListResponse</returns>
    public static FileList List(DriveService service, FilesListOptionalParms optional = null)
    {
        try
        {
            // Initial validation.
            if (service == null)
                throw new ArgumentNullException("service");

            // Building the initial request.
            var request = service.Files.List();

            // Applying optional parameters to the request.                
            request = (FilesResource.ListRequest)SampleHelpers.ApplyOptionalParms(request, optional);

            // Requesting data.
            return request.Execute();
        }
        catch (Exception ex)
        {
            throw new Exception("Request Files.List failed.", ex);
        }
    }

As for your your first question i am still trying to get the search to return only files that were created by you. I can get the ones owned by created by doesnt seam to be an option. still trying

Update:

It seams that there is no way of getting createdby there is only a createdtime. The best i could do was find files owned by you which i guess it would be if you created it. However if you transferred ownership to someone else after you created it then well you wouldn't know.

'me' in owners
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449