コード例 #1
0
        public static GDriveFile GetFolderTree(string directoryPath)
        {
            var splitDirectories = directoryPath.Split(new char[] { '/', '\\' });
            var root             = service.Files.Get("root").Execute();

            GDriveFile gDriveFile = new GDriveFile()
            {
                FileId        = root.Id,
                FileName      = root.Name,
                MimeType      = root.MimeType,
                LengthInBytes = root.Size,
                IsFolder      = true,
                File          = root
            };

            GDriveFile currentFile = gDriveFile;

            for (int i = 0; i < splitDirectories.Length; i++)
            {
                var dir   = splitDirectories[i];
                var child = GetChildFolderByName(currentFile, dir);
                currentFile = child;
            }

            return(gDriveFile);
        }
コード例 #2
0
        public static GDriveFile GetLastFolderInTree(GDriveFile tree)
        {
            var currentNode = tree;

            do
            {
                currentNode = currentNode.Children.FirstOrDefault();
            } while (currentNode != null && currentNode.Children.Count > 0);
            return(currentNode);
        }
コード例 #3
0
        public static GDriveFile GetParentDetail(GDriveFile gDriveFile, bool recursive)
        {
            var dirId = gDriveFile.Parent.FileId;

            var fileRequest = service.Files.Get(dirId);//.List();

            fileRequest.Fields = "*";

            var dirFiles = fileRequest.Execute();

            if (dirFiles != null)
            {
                var        file        = dirFiles;
                GDriveFile gDriveFile1 = new GDriveFile()
                {
                    FileId        = file.Id,
                    FileName      = file.Name,
                    MimeType      = file.MimeType,
                    LengthInBytes = file.Size,
                    IsFolder      = true,
                    File          = file
                };

                if (file.Parents != null && file.Parents.Count > 0)
                {
                    gDriveFile1.Parent = new GDriveFile()
                    {
                        FileId = file.Parents[0]
                    }
                }
                ;

                gDriveFile.Parent = gDriveFile1;

                if (recursive && gDriveFile1.Parent != null && !string.IsNullOrWhiteSpace(gDriveFile1.Parent.FileId))
                {
                    gDriveFile1 = GetParentDetail(gDriveFile1, recursive);
                }
            }

            return(gDriveFile);
        }
コード例 #4
0
        public static GDriveFile GetChildFileByName(GDriveFile file, string name)
        {
            var fileRequest = service.Files.List();

            fileRequest.Q      = $"'{file.FileId}' in parents and trashed = false and mimeType != 'application/vnd.google-apps.folder'";
            fileRequest.Fields = "*";

            var filess = fileRequest.Execute().Files;
            var dir    = fileRequest.Execute().Files.Where(m => m.Name == name).FirstOrDefault();

            GDriveFile gDriveFile = new GDriveFile()
            {
                FileId        = dir.Id,
                FileName      = dir.Name,
                MimeType      = dir.MimeType,
                LengthInBytes = dir.Size,
                IsFolder      = true,
                File          = dir
            };

            file.Children.Add(gDriveFile);
            return(gDriveFile);
        }