DeleteIfExists() public method

Deletes the blob if it exists.
public DeleteIfExists ( ) : bool
return bool
Esempio n. 1
0
        private const string MimeTypeName = "text/plain"; // since these are assumed to

        #endregion Fields

        #region Methods

        /// <summary>
        /// ugliness of downloading and reuploading whole blob.
        /// </summary>
        /// <param name="blob"></param>
        /// <param name="toAdd"></param>
        public static void appendToBlob(CloudBlob blob, string toAdd)
        {
            string oldLogData = "";
            if (Exists(blob))
                oldLogData = blob.DownloadText();
            blob.DeleteIfExists();
            blob.UploadText(oldLogData + "\r\n" + toAdd);
        }
 /// <summary>
 /// Удаляет файл.
 /// </summary>
 /// <param name="localUri"> Адрес файла </param>
 public void Delete(string localUri)
 {
     CloudBlob blob = new CloudBlob(localUri, _client);
     blob.DeleteIfExists(new BlobRequestOptions()
     {
         RetryPolicy = RetryPolicies.RetryExponential(
             RetryPolicies.DefaultClientRetryCount,
             RetryPolicies.DefaultClientBackoff)
     });
 }
        internal static void MoveBlob(CloudBlob blob, string topath = "", string currentpath = "")
        {
            // Retrieve stroage account from connection string
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            // Create the blob client
            CloudBlobClient client = storageAccount.CreateCloudBlobClient();

            CloudBlobContainer blobContainer = null;
            CloudBlobDirectory toFolder = null;

            CloudBlob newblob = null;

            if (topath.Contains('/')) {
                toFolder = client.GetBlobDirectoryReference(topath);
                string filepath = blob.Name.Substring(blob.Name.IndexOf("/") + 1);
                newblob = toFolder.GetBlobReference(filepath);
            } else {
                blobContainer = client.GetContainerReference(topath);
                string filepath = blob.Name.Substring(blob.Name.IndexOf("/") + 1);
                newblob = blobContainer.GetBlobReference(filepath);
            }
            newblob.UploadByteArray(blob.DownloadByteArray());
            blob.DeleteIfExists();
        }
		public TaskRunner CreateFileNotExistsTaskRunner(CloudBlob blob, string basePath)
		{
			this._statistics.FileNotExistCount++;
			return new SingleActionTaskRunner(() =>
			{
				string relativePath = blob.GetRelativeFilePath();
				string fullFilePath = this._fileSystem.Combine(basePath, relativePath);

				_messageBus.Publish(new FileProgressedMessage(fullFilePath, 0));
				blob.DeleteIfExists();
				_messageBus.Publish(new FileProgressedMessage(fullFilePath, 1));
			});
		}