0

I have a piece of code which iterates over file share and delete the file share, while deleting it may contain snapshots ,how do I delete file share as it keeps failing with Error Message like . "Unable to delete file share because one or more share snapshots have active leases, Note: I could not see any properties letting me know lease ID and even snapshot time is null .Over Portal there is a delete lock at storage account level ,does it restrict the deletion of file shares ?

using Microsoft.WindowsAzure.Storage
string storageconnectionstring = "Storage Account connection string";
CloudStorageAccount c = CloudStorageAccount.Parse(storageconnectionstring);
CloudFileClient fileclient= c.CreateCloudFileClient();


foreach(var x in fileclient.ListShares()) {

x.DeleteIfExists(DeleteShareSnapshotsoptions.IncludeSnapshots ,AccessCondition.GenerateEmpty(),
new FileRequestOptions(), new OperationContext())----> This code is failing

}
Code_1993
  • 127
  • 1
  • 4
  • 16

1 Answers1

1

I tried in my environment and got below results:

"Unable to delete file share because one or more share snapshots have active leases,

The error shows in your File-share has some active snapshots so that cannot be deleted.

I tried in my environment with piece of code to delete the snapshots.

You can use the **azure.storage.files.share**package to able to delete the snapshots.

Code:

using Azure.Storage.Files.Shares;

namespace fileshare
{
    class program
    {
        public static void Main()
        {
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=<Account name>;AccountKey=<Account key >==;EndpointSuffix=core.windows.net";
            var shareName = "share1";
            var snapshot = "2022-10-22T10:23:02.0000000Z";
            ShareServiceClient shareserviceclient = new ShareServiceClient(connectionString);
            ShareClient shareClient = shareserviceclient.GetShareClient(shareName).WithSnapshot(snapshot);
            shareClient.Delete();
        }
    }
}

Response:

enter image description here

Portal:

Venkatesan
  • 3,748
  • 1
  • 3
  • 15