예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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();
        }
예제 #4
0
        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();
        }
예제 #5
0
        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();
 }
예제 #7
0
 public bool Exists(string filePath)
 {
     return(GDriveHelper.GetFileByPath(filePath) != null);
 }
예제 #8
0
        public void Delete(string filePath)
        {
            var file = GDriveHelper.GetFileByPath(filePath);

            service.Files.Delete(file.FileId);
        }
예제 #9
0
        //TODO: Implement destiFilePath
        public void CopyTo(string sourceFilePath, string destiFilePath)
        {
            var file = GDriveHelper.GetFileByPath(sourceFilePath);

            service.Files.Copy(file.File, "");
        }
예제 #10
0
 public GDriveFile()
 {
     service       = GDriveHelper.GetService();
     this.Children = new List <GDriveFile>();
 }
예제 #11
0
        public byte[] ReadAllBytes(string filePath)
        {
            var ms = Read(filePath);

            return(GDriveHelper.StreamToByteArray(ms));
        }