Beispiel #1
0
        /// <summary>
        /// Insert a new permission.
        /// </summary>
        /// <param name="service">Drive API service instance.</param>
        /// <param name="fileId">ID of the file to insert permission for.</param>
        /// <param name="who">
        /// User or group e-mail address, domain name or null for "default" type.
        /// </param>
        /// <param name="type">The value "user", "group", "domain" or "default".</param>
        /// <param name="role">The value "owner", "writer" or "reader".</param>
        /// <returns>The inserted permission, null is returned if an API error occurred</returns>
        private Permission InsertPermission(DriveService service, string fileId, string who, string type, string role)
        {
            Permission newPermission = new Permission
            {
                EmailAddress = who,
                Type         = type,
                Role         = role
            };

            try
            {
                CreateRequest req = service.Permissions.Create(newPermission, fileId);
                req.SendNotificationEmail = false;
                req.Execute();
            }
            catch (Exception e)
            {
                throw new Exception("An error occurred: " + e.Message);
            }
            return(null);
        }
        public static Google.Apis.Drive.v3.Data.File CreateFolder(string FolderName, string ParentID = null)
        {
            ParentID = ParentID ?? ParentDrive;
            var folderMetadata = new Google.Apis.Drive.v3.Data.File
            {
                Name     = FolderName,
                MimeType = "application/vnd.google-apps.folder",
                Parents  = new List <string>
                {
                    ParentID,
                }
            };

            CreateRequest CreateFolderRequest = driveService.Files.Create(folderMetadata);

            CreateFolderRequest.Fields            = "id";
            CreateFolderRequest.SupportsAllDrives = true;

            var folder = CreateFolderRequest.Execute();

            return(folder);
        }