public GoogleFolder CreateFolder(GoogleFolder parentFolder, string folderName) { var guid = Guid.NewGuid(); File body = new File(); body.Title = folderName; body.Description = string.Format("Create by FileSync on: {0}", DateTime.Now); body.MimeType = "application/vnd.google-apps.folder"; if (parentFolder != null) { body.Parents = new List <ParentReference>() { new ParentReference() { Id = parentFolder.Id } }; } File file = _service.Files.Insert(body).Execute(); return(new GoogleFolder(file.Id, file.Title)); }
public bool DoesFileExistInFolder(GoogleFolder parentFolder, string fileName) { // Define parameters of request. FilesResource.ListRequest findFolderRequest = _service.Files.List(); findFolderRequest.Q = string.Format("trashed=false and '{0}' in parents and title='{1}'", parentFolder.Id, fileName); // List files. IList <File> files = findFolderRequest.Execute().Items; return(files.Any()); }
public GoogleFile UploadFile(GoogleFolder parentFolder, string fileName, string fullLocation, string mimeType) { if (System.IO.File.Exists(fullLocation)) { File body = new File(); body.Title = fileName; body.Description = "File synced from local location: " + fullLocation; body.MimeType = mimeType; body.Parents = new List <ParentReference>() { new ParentReference() { Id = parentFolder.Id } }; // File's content. byte[] byteArray = System.IO.File.ReadAllBytes(fullLocation); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); try { FilesResource.InsertMediaUpload request = _service.Files.Insert(body, stream, mimeType); request.Upload(); var uploadedFile = request.ResponseBody; return(new GoogleFile(uploadedFile.Id, uploadedFile.Title)); } catch (Exception e) { //todo log return(null); } } else { //todo log return(null); } }