azure Azure Storage Options Renaming a blob file in Azure Blob Storage

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


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][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();

For more information, see How to rename a blob file in Azure Blob Storage

Got any azure Question?