Esempio n. 1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            switch (ParameterSetName)
            {
            case ParameterSetNames.FromName:
                // We just use Bucket and ObjectName.
                break;

            case ParameterSetNames.FromObject:
                Bucket     = Object.Bucket;
                ObjectName = Object.Name;
                break;

            default:
                throw UnknownParameterSetException;
            }

            if (!ShouldProcess($"[{Bucket}] {ObjectName}", "Delete Object"))
            {
                return;
            }

            ObjectsResource.DeleteRequest delReq = Service.Objects.Delete(Bucket, ObjectName);
            string result = delReq.Execute();

            if (!string.IsNullOrWhiteSpace(result))
            {
                WriteObject(result);
            }
        }
        // To delete the file:
        public void Delete(string bucketName)
        {
            ObjectsResource.DeleteRequest deleteRequest = null;

            deleteRequest            = new ObjectsResource.DeleteRequest(_storageService, bucketName, "keyName");
            deleteRequest.OauthToken = _userCredential.Token.AccessToken;
            deleteRequest.Execute();
        }
Esempio n. 3
0
        public bool DeleteFile(string fileId)
        {
            var newObject = new Google.Apis.Storage.v1.Data.Object()
            {
                Bucket = BucketToUpload,
                Name   = fileId
            };
            string resultStatus;

            try
            {
                var deleteRequest = new ObjectsResource.DeleteRequest(StorageService,
                                                                      BucketToUpload, fileId);
                resultStatus = deleteRequest.Execute();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(true);
        }