예제 #1
0
        public static List <GoogleDriveFiles> GetSubDriveFiles(string folderId)
        {
            DriveService service = GetService();

            // define parameters of request.
            FilesResource.ListRequest FileListRequest = service.Files.List();
            FileListRequest.Q = "'" + folderId + "' in parents and trashed=false ";
            //listRequest.PageSize = 10;
            //listRequest.PageToken = 10;
            FileListRequest.Fields = "nextPageToken, files(id, name, size, version,parents,thumbnailLink,webContentLink,webViewLink,createdTime)";

            //get file list.
            IList <Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
            List <GoogleDriveFiles> FileList             = new List <GoogleDriveFiles>();
            int number = 0;

            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    //if (file.Parents != null)
                    //{
                    number++;
                    GoogleDriveFiles File = new GoogleDriveFiles
                    {
                        Num            = number,
                        Id             = file.Id,
                        Name           = file.Name,
                        Size           = file.Size,
                        Version        = file.Version,
                        Parents        = file.Parents,
                        ThumbnailLink  = file.ThumbnailLink,
                        WebContentLink = file.WebContentLink,
                        WebViewLink    = file.WebViewLink,
                        CreatedTime    = file.CreatedTime
                    };
                    FileList.Add(File);
                    // }
                }
            }

            return(FileList);
        }
예제 #2
0
        //get all files from Google Drive.
        public static List <GoogleDriveFiles> GetDriveFiles()
        {
            DriveService service = GetService();

            // define parameters of request.
            FilesResource.ListRequest FileListRequest = service.Files.List();
            FileListRequest.Q = "'0B9hgKCBhg5FsZUlVT2swWlVIeGs' in parents and trashed=false ";
            //listRequest.PageSize = 10;
            //listRequest.PageToken = 10;
            FileListRequest.Fields = "nextPageToken, files(id, name, size, version,parents,thumbnailLink,webContentLink,webViewLink,createdTime)";

            //get file list.
            IList <Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
            List <GoogleDriveFiles> FileList             = new List <GoogleDriveFiles>();
            int number = 0;

            if (files != null && files.Count > 0)
            {
                foreach (var file in files)
                {
                    if (!file.Name.Contains("MUCLUC") && !file.Name.Contains("MUC LUC") && !file.Name.Contains("BOSUNG") && !file.Name.Contains("TAILIEUHUONGDAN") && !file.Name.Contains("PHIEUKIEMTRA"))
                    {
                        number++;
                        GoogleDriveFiles File = new GoogleDriveFiles
                        {
                            Num            = number,
                            Id             = file.Id,
                            Name           = file.Name,
                            Size           = file.Size,
                            Version        = file.Version,
                            Parents        = file.Parents,
                            ThumbnailLink  = file.ThumbnailLink,
                            WebContentLink = file.WebContentLink,
                            WebViewLink    = file.WebViewLink,
                            CreatedTime    = file.CreatedTime
                        };
                        FileList.Add(File);
                    }
                }
            }

            return(FileList);
        }