azureazure-filesazure-storage-filesfilesharestorage-file-share

How can I set lease duration on azure fileshare leased file?


I am trying to set expiry for acquired leased as 1 min. This is my code

var shareClient = new ShareClient(connectionString, "testfileshare");
shareClient.CreateIfNotExists();
var fileClient = shareClient.GetRootDirectoryClient().GetFileClient("test.xml"); 
var leaseClient = fileClient.GetShareLeaseClient();
                
leaseClient.Acquire(TimeSpan.FromSeconds(60));
 var leaseDuration = fileClient.GetProperties().Value.LeaseDuration;

With above code leaseDuration is set to infinite. I would like to set this to 1 min.


Solution

  • It is not possible to set the lease duration for a file in a file share. You can only acquire an infinite lease on a file (though it is possible to acquire a finite lease on a file share).

    From the REST API documentation:

    enter image description here