public static GDriveFile GetFileByPath(string filePath) { var tree = GetFolderTree(filePath); var lastFolder = GetLastFolderInTree(tree); var file = GDriveHelper.GetChildFileByName(lastFolder, filePath.Split(new char[] { '/', '\\' }).LastOrDefault()); return(file); }
public Stream Read(string filePath) { var file = GDriveHelper.GetFileByPath(filePath); var request = service.Files.Get(file.FileId); MemoryStream memoryStream = new MemoryStream(); request.Download(memoryStream); return(memoryStream); }
public void Rename(string filePath, string newFileName) { var file = GDriveHelper.GetFileByPath(filePath); Google.Apis.Drive.v3.Data.File gfile = new Google.Apis.Drive.v3.Data.File() { Name = newFileName }; var updateRequest = service.Files.Update(gfile, file.FileId); updateRequest.Fields = "name"; updateRequest.Execute(); }
public void MoveTo(string sourceFilePath, string destiFilePath) { var file = GDriveHelper.GetFileByPath(sourceFilePath); var updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), file.FileId); GDriveDirectory gDriveDirectory = new GDriveDirectory(); if (!gDriveDirectory.Exists(destiFilePath)) { throw new DirectoryNotFoundException(destiFilePath + " does not exists"); } var tree = GDriveHelper.GetFolderTree(destiFilePath); var lastFolder = GDriveHelper.GetLastFolderInTree(tree); updateRequest.AddParents = lastFolder.FileId; updateRequest.RemoveParents = file.File.Parents[0]; updateRequest.Execute(); }
public string GetFullPath() { List <string> lstPath = new List <string>(); if (this.Parent != null && !string.IsNullOrWhiteSpace(this.Parent.FileId)) { var a = GDriveHelper.GetParentDetail(this, true); var currentNode = a; do { lstPath.Add(currentNode.FileName); if (currentNode.Parent != null) { currentNode = currentNode.Parent; } } while (currentNode.Parent != null && currentNode.IsFolder); } lstPath.Reverse(); return(string.Join("/", lstPath)); }
public GDriveDirectory() { service = GDriveHelper.GetService(); }
public bool Exists(string filePath) { return(GDriveHelper.GetFileByPath(filePath) != null); }
public void Delete(string filePath) { var file = GDriveHelper.GetFileByPath(filePath); service.Files.Delete(file.FileId); }
//TODO: Implement destiFilePath public void CopyTo(string sourceFilePath, string destiFilePath) { var file = GDriveHelper.GetFileByPath(sourceFilePath); service.Files.Copy(file.File, ""); }
public GDriveFile() { service = GDriveHelper.GetService(); this.Children = new List <GDriveFile>(); }
public byte[] ReadAllBytes(string filePath) { var ms = Read(filePath); return(GDriveHelper.StreamToByteArray(ms)); }