Renaming a blob file in Azure Blob Storage - Azure tutorial



  • There’s no API that can rename the blob file on Azure. This code snippet demonstrates how to rename a blob file in Microsoft Azure Blob Storage.
StorageCredentials cred = new StorageCredentials("[Your storage account name]", "[Your storage account key]");

CloudBlobContainer container = new CloudBlobContainer(new Uri("http://[Your storage account name].blob.core.windows.net/[Your container name] /"), cred); 

string fileName = "OldFileName"; 
string newFileName = "NewFileName";

CloudBlockBlob blobCopy = container.GetBlockBlobReference(newFileName);   

if (!await blobCopy.ExistsAsync())  
{
    CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

    if (await blob.ExistsAsync())
    {
        await blobCopy.StartCopyAsync(blob);  
        await blob.DeleteIfExistsAsync();
    }
} 

Related Searches to Renaming a blob file in Azure Blob Storage - Azure tutorial