'how to copy all files from a directory and move the copy of those file to different directory in same azure blob container c#
I am a newbie to c# and .net and Azure developement i wanna copy all files from a directory and move the copy of those file to different directory in same azure blob container so that i can work with the copy of file when the original file is safe. But had no idea how to do so..
Solution 1:[1]
I have tested in my environment
You can use the below code to copy blobs from one directory to another directory in a same container in Azure Blob Storage:
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
var connectionString = "StorageAccountConnectionString";
string containerName = "ContainerName";
string directory1 = "SourceDirectory";
string directory2 = "TargetDirectory";
var serviceClient = new BlobServiceClient(connectionString);
var containerClient = serviceClient.GetBlobContainerClient(containerName);
foreach (BlobItem blob in containerClient.GetBlobs())
{
if (blob.Name.Contains(directory1))
{
var blobUri = containerClient.GetBlobClient(blob.Name);
var newBlob = containerClient.GetBlobClient(blob.Name.Replace(directory1,directory2));
newBlob.StartCopyFromUri(blobUri.Uri);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RamaraoAdapa-MT |
