// Display list audio public static List <GoogleDriveFiles> Index() { Google.Apis.Drive.v3.DriveService service = GetService(); // define parameters of request. Google.Apis.Drive.v3.FilesResource.ListRequest FileListRequest = service.Files.List(); //listRequest.PageSize = 10; //listRequest.PageToken = 10; FileListRequest.Fields = "nextPageToken, files(createdTime, id, name, size, version, trashed, parents)"; //get file list. IList <Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files; 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, Parents = file.Parents }; string path = Path.Combine(HttpContext.Current.Server.MapPath("~"), Path.GetFileName(file.Name)); var fileMETA = new Google.Apis.Drive.v3.Data.File() { Name = file.Name, MimeType = MimeMapping.GetMimeMapping(path) }; if (fileMETA.MimeType == "audio/mpeg" || fileMETA.MimeType == "audio/wav") { FileList.Add(File); } } } return(FileList); }
//Delete file from the Google drive public static void DeleteFile(GoogleDriveFiles files) { Google.Apis.Drive.v3.DriveService service = GetService(); try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (files == null) { throw new ArgumentNullException(files.Id); } // Make the request. service.Files.Delete(files.Id).Execute(); } catch (Exception ex) { throw new Exception("Request Files.Delete failed.", ex); } }