You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### Example: Lock a file in a file share using System.IO
230
230
231
-
The following code example shows how to lock a file in a file share:
231
+
SMB clients that mount file shares can use file system locking mechanisms to manage access to shared files.
232
+
233
+
The following code example shows how to lock a file in a file share with share mode set to `None`. This share mode declines sharing of the current file until the file is closed.
When using both SMB and the FileREST API, be aware that the FileREST API uses [leases](#example-lease-a-file-using-the-file-shares-client-library) to manage file locks, while SMB uses file system locks managed by the operating system. To learn more about managing file locking interactions between SMB and the FileREST API, see [Manage file locks](/rest/api/storageservices/managing-file-locks).
265
+
262
266
### Example: Enumerate file ACLs using System.IO
263
267
264
268
The following code example shows how to enumerate ACLs for a file:
## Lease a file using the File Shares client library
443
+
### Example: Lease a file using the File Shares client library
439
444
440
-
A lease creates a lock on a file that's managed by Azure via a lease ID. The lease provides a mechanism to coordinate access to files across multiple clients in a distributed system. A lease on a file provides exclusive write and delete access. To learn more about lease duration and actions, see [Lease File](/rest/api/storageservices/lease-file).
445
+
A lease creates a lock on a file that's managed by Azure via a lease ID. The lease provides a mechanism to coordinate access to files across multiple clients in a distributed system. A lease on a file provides exclusive write and delete access. To learn more about lease states and actions, see [Lease File](/rest/api/storageservices/lease-file#remarks).
441
446
442
-
The following code example shows how to acquire a lease on a file:
447
+
The following code example shows how to create a lease client, acquire a infinite duration lease on a file, and release the lease:
443
448
444
449
```csharp
450
+
string accountName = "<account-name>";
451
+
string shareName = "sample-file-share";
452
+
string filePath = "path/to/file";
453
+
454
+
TokenCredential tokenCredential = new DefaultAzureCredential();
455
+
456
+
ShareClientOptions options = new()
457
+
{
458
+
ShareTokenIntent = ShareTokenIntent.Backup,
459
+
};
460
+
461
+
ShareFileClient fileClient = new(
462
+
new Uri($"https://{accountName}.file.core.windows.net/{shareName}/{filePath}"),
When using both SMB and the FileREST API, be aware that the FileREST API uses [leases](#example-lease-a-file-using-the-file-shares-client-library) to manage file locks, while SMB uses file system locks managed by the operating system. To learn more about managing file locking interactions between SMB and the FileREST API, see [Manage file locks](/rest/api/storageservices/managing-file-locks).
478
+
479
+
### Example: Create and list share snapshots using the File Shares client library
480
+
481
+
Share snapshots are read-only copies of a file share at a point in time. You can create a snapshot of a file share, and then use the snapshot to access the data in the share at the time the snapshot was created. You can also list all snapshots in a file share, and delete share snapshots.
482
+
483
+
The following code example shows how to create a share snapshot, list the snapshots in a file share, and traverse the directory tree in a share snapshot:
484
+
485
+
```csharp
486
+
string connectionString = "<connection-string>";
487
+
488
+
ShareServiceClient shareServiceClient = new ShareServiceClient(connectionString);
> OAuth tokens, such as those obtained when using `DefaultAzureCredential`, aren't allowed for data plane operations at the file share level. To work with share snapshots, the client object must be authorized using the account key. The `ShareClient` object created in this code example uses a connection string, which includes the account key.
533
+
>
534
+
> Storing account keys or connection strings presents a security risk. You should only use them when Microsoft Entra authentication isn't available. To learn more about securely storing account keys in Azure Key Vault, see [About Azure Key Vault managed storage account keys](/azure/key-vault/secrets/about-managed-storage-account-keys).
535
+
447
536
## Manage Azure Files resources using the Azure Storage management libraries
448
537
449
538
The Azure Storage management libraries are built on the Azure Storage resource provider REST API. The Azure Storage resource provider is a service based on [Azure Resource Manager](/azure/azure-resource-manager/management/overview), and supports both declarative (templates) and imperative (direct API call) methods. The Azure Storage resource provider REST API provides programmatic access to Azure Storage resources, including file shares. The Azure SDK provides management libraries that build on the Azure Storage resource provider REST API.
@@ -514,16 +603,18 @@ await foreach (FileShareResource shareResource in fileService.GetFileShares().Ge
For more information about Azure Files, see the following resources:
613
+
For more information about developing with Azure Files, see the following resources:
614
+
615
+
- [Overview of application development with Azure Files](storage-files-developer-overview.md)
616
+
- [Naming and referencing shares, directories, files, and metadata](/rest/api/storageservices/naming-and-referencing-shares--directories--files--and-metadata)
0 commit comments