Skip to content

Commit 2a7dd2b

Browse files
Add examples
1 parent 15d252f commit 2a7dd2b

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

articles/storage/files/storage-dotnet-how-to-use-files.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,14 +397,42 @@ To learn more about each of these authorization mechanisms, see [Choose how to a
397397
398398
### Example: Copy files using the File Shares client library
399399
400-
The following code example shows how to copy a file to another file:
400+
You can copy files within a file share or between file shares by using the following method:
401401
402-
```csharp
403-
```
402+
- [StartCopyAsync](/dotnet/api/azure.storage.files.shares.sharefileclient.startcopyasync)
403+
404+
You can copy a file to a destination blob by using the following method from a `BlobClient` object:
405+
406+
- [StartCopyFromUriAsync](/dotnet/api/azure.storage.blobs.specialized.blobbaseclient.startcopyfromuriasync)
404407
405-
The following code example shows how to copy a file to a blob:
408+
The following code example shows how to copy a file to a file in another file share:
406409
407410
```csharp
411+
string accountName = "<account-name>";
412+
string srcShareName = "src-file-share";
413+
string destShareName = "dest-file-share";
414+
string srcFilePath = "src/path/to/file";
415+
string destFilePath = "dest/path/to/file";
416+
417+
TokenCredential tokenCredential = new DefaultAzureCredential();
418+
419+
ShareFileClient srcShareFileClient = new(
420+
new Uri($"https://{accountName}.file.core.windows.net/{srcShareName}/{srcFilePath}"),
421+
tokenCredential);
422+
423+
ShareClientOptions options = new()
424+
{
425+
ShareTokenIntent = ShareTokenIntent.Backup,
426+
};
427+
428+
ShareFileClient destShareFileClient = new(
429+
new Uri($"https://{accountName}.file.core.windows.net/{destShareName}/{destFilePath}"),
430+
tokenCredential,
431+
options);
432+
433+
// Copy the file from the source share to the destination share
434+
435+
await destShareFileClient.StartCopyAsync(srcShareFileClient.Uri);
408436
```
409437
410438
## Manage Azure Files resources using the Azure Storage management libraries

0 commit comments

Comments
 (0)