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
Copy file name to clipboardExpand all lines: articles/storage/files/storage-dotnet-how-to-use-files.md
+86-9Lines changed: 86 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,9 +42,8 @@ For general information about these approaches, see [Overview of application dev
42
42
This article focuses on working with Azure Files resources using the following approaches:
43
43
44
44
-[Work with Azure Files using System.IO](#work-with-azure-files-using-systemio): Mount a file share using SMB or NFS and use the `System.IO` namespace to work with files and directories in the share.
45
-
-[Work with Azure Files using the File Shares client library for .NET](#work-with-azure-files-using-the-file-shares-client-library-for-net): Use the Azure Storage File Shares client library for .NET to work with files and directories in a file share. This client library builds on the FileREST API.
46
-
47
-
To learn about using the Storage resource provider REST API and management libraries, see [Libraries for resource management](storage-files-developer-overview.md#libraries-for-resource-management).
45
+
-[Work with Azure Files using the File Shares client library for .NET](#work-with-azure-files-data-using-the-file-shares-client-library-for-net): Use the Azure Storage File Shares client library for .NET to work with files and directories in a file share. This client library builds on the FileREST API.
46
+
-[Manage Azure Files resources using the Azure Storage management libraries](#manage-azure-files-resources-using-the-azure-storage-management-libraries): Use the Azure Storage management libraries to manage file shares and other resources in your storage account. The management libraries build on the Azure Storage resource provider REST API.
48
47
49
48
## Prerequisites
50
49
@@ -93,21 +92,23 @@ If you don't already have a .NET app, create one using Visual Studio or the .NET
93
92
94
93
### Install the package
95
94
96
-
If you plan to interact with Azure Files using the `System.IO` namespace, you don't need to install any additional packages. The `System.IO` namespace is included with the .NET SDK. If you plan to use the File Shares client library for .NET, install the package using NuGet.
95
+
If you plan to interact with Azure Files using the `System.IO` namespace, you don't need to install any additional packages. The `System.IO` namespace is included with the .NET SDK. If you plan to use the File Shares client library for .NET or the Azure Storage management library for .NET, install the package using NuGet.
97
96
98
97
### [Visual Studio](#tab/visual-studio)
99
98
100
99
1. In **Solution Explorer**, right-click your project and choose **Manage NuGet Packages**.
101
-
1. In **NuGet Package Manager**, select **Browse**. Then search for and choose **Azure.Storage.Files.Shares**. Select **Install**.
100
+
1. In **NuGet Package Manager**, select **Browse**. Then search for and choose the appropriate package and select **Install**. For the File Shares client library, choose **Azure.Storage.Files.Shares**. For the Azure Storage management library, choose **Azure.ResourceManager.Storage**. For the Azure Identity library, which is needed for passwordless choose **Azure.Identity**.
102
101
103
102
This step installs the package and its dependencies.
104
103
105
104
### [.NET CLI](#tab/dotnet-cli)
106
105
107
-
1. In a console window, run the following command to install the `Azure.Storage.Files.Shares` package.
106
+
1. In a console window, run the following command to install the `Azure.Storage.Files.Shares` or the `Azure.ResourceManager.Storage` package. You can also install the `Azure.Identity` package to use the `DefaultAzureCredential` class for authentication.
108
107
109
108
```dotnetcli
110
109
dotnet add package Azure.Storage.Files.Shares
110
+
dotnet add package Azure.ResourceManager.Storage
111
+
dotnet add package Azure.Identity
111
112
```
112
113
113
114
---
@@ -126,6 +127,18 @@ If you plan to use the File Shares client library for .NET, add the following us
126
127
using Azure.Storage.Files.Shares;
127
128
```
128
129
130
+
If you plan to use the Azure Storage management library for .NET, add the following using directive to the top of your *Program.cs* file:
131
+
132
+
```csharp
133
+
using Azure.ResourceManager;
134
+
```
135
+
136
+
To use the Azure Identity library for passwordless connections to Azure services, add the following using directive to the top of your *Program.cs* file:
137
+
138
+
```csharp
139
+
using Azure.Identity;
140
+
```
141
+
129
142
## Work with Azure Files using System.IO
130
143
131
144
Standard file I/O libraries are the most common way to access and work with Azure Files resources. When you mount a file share using SMB or NFS, your operating system redirects API requests for the local file system. This approach allows you to use standard file I/O libraries, such as `System.IO`, to interact with files and directories in the share.
## Work with Azure Files using the File Shares client library for .NET
295
+
## Work with Azure Files data using the File Shares client library for .NET
283
296
284
297
The FileREST API provides programmatic access to Azure Files. It allows you to call HTTPS endpoints to perform operations on file shares, directories, and files. The FileREST API is designed for high scalability and advanced features that might not be available through native protocols. The Azure SDK provides client libraries, such as the File Shares client library for .NET, that build on the FileREST API.
285
298
@@ -289,7 +302,7 @@ Consider using the FileREST API and the File Share client library if your applic
289
302
- **Custom cloud integrations:** Build custom value-added services, such as backup, antivirus, or data management, that interact directly with Azure Files.
290
303
- **Performance optimization:** Benefit from performance advantages in high-scale scenarios using data plane operations.
291
304
292
-
The FileREST API models Azure Files as a hierarchy of resources, and is recommended for operations that are performed at the *directory* or *file* level. You should prefer the Storage resource provider REST API for operations that are performed at the *file service* or *file share* level.
305
+
The FileREST API models Azure Files as a hierarchy of resources, and is recommended for operations that are performed at the *directory* or *file* level. You should prefer the [Storage resource provider REST API](#manage-azure-files-resources-using-the-azure-storage-management-libraries) for operations that are performed at the *file service* or *file share* level.
293
306
294
307
In this section, you learn how to use the File Shares client library to work with Azure Files resources.
295
308
@@ -382,7 +395,71 @@ For information about how to obtain account keys and best practice guidelines fo
382
395
383
396
To learn more about each of these authorization mechanisms, see [Choose how to authorize access to file data](authorize-data-operations-portal.md).
384
397
385
-
### Example: TODO:Add examples here
398
+
### Example: Copy files using the File Shares client library
399
+
400
+
The following code example shows how to copy a file to another file:
401
+
402
+
```csharp
403
+
```
404
+
405
+
The following code example shows how to copy a file to a blob:
406
+
407
+
```csharp
408
+
```
409
+
410
+
## Manage Azure Files resources using the Azure Storage management libraries
411
+
412
+
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.
413
+
414
+
The management libraries are recommended for operations that are performed at the *file service* or *file share* level. In this section, you learn how to use the Azure Storage management libraries to manage Azure Files resources.
415
+
416
+
### Example: Create a file share using the Azure Storage management library
417
+
418
+
The following code example shows how to create a top-level `ArmClient` object, register the Storage resource provider with a subscription, and create a file share using the Azure Storage management library:
419
+
420
+
```csharp
421
+
ArmClient armClient = new ArmClient(new DefaultAzureCredential());
422
+
423
+
// Create a resource identifier, then get the subscription resource
You can configure the file share properties using the [FileShareData](/dotnet/api/azure.resourcemanager.storage.filesharedata) class. The previous example shows how to set the `ShareQuota` property.
460
+
461
+
>[!NOTE]
462
+
> To perform the register operation, you need permissions for the following Azure RBAC action: Microsoft.Storage/register/action. This permission is included in the Contributor and Owner built-in roles.
0 commit comments