Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article shows you how to connect to Azure Blob Storage by using the Azure Blob Storage client library for .NET. Once connected, use the developer guides to learn how your code can operate on containers, blobs, and features of the Blob Storage service.
If you're looking to start with a complete example, see Quickstart: Azure Blob Storage client library for .NET.
API reference | Library source code | Package (NuGet) | Samples | Give feedback
This section walks you through preparing a project to work with the Azure Blob Storage client library for .NET.
From your project directory, install packages for the Azure Blob Storage and Azure Identity client libraries using the dotnet add package
command. The Azure.Identity package is needed for passwordless connections to Azure services.
dotnet add package Azure.Storage.Blobs
dotnet add package Azure.Identity
Add these using
directives to the top of your code file:
using Azure.Identity;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
Blob client library information:
Azure.Storage.Blobs: Contains the primary classes (client objects) that you can use to operate on the service, containers, and blobs.
Azure.Storage.Blobs.Specialized: Contains classes that you can use to perform operations specific to a blob type, such as block blobs.
Azure.Storage.Blobs.Models: All other utility classes, structures, and enumeration types.
To connect an app to Blob Storage, create an instance of the BlobServiceClient class. This object is your starting point to interact with data resources at the storage account level. You can use it to operate on the storage account and its containers. You can also use the service client to create container clients or blob clients, depending on the resource you need to work with.
To learn more about creating and managing client objects, see Create and manage client objects that interact with data resources.
You can authorize a BlobServiceClient
object by using a Microsoft Entra authorization token, an account access key, or a shared access signature (SAS). For optimal security, Microsoft recommends using Microsoft Entra ID with managed identities to authorize requests against blob data. For more information, see Authorize access to blobs using Microsoft Entra ID.
Create a StorageSharedKeyCredential by using the storage account name and account key. Then use that object to initialize a BlobServiceClient.
public static void GetBlobServiceClient(ref BlobServiceClient blobServiceClient,
string accountName, string accountKey)
{
Azure.Storage.StorageSharedKeyCredential sharedKeyCredential =
new StorageSharedKeyCredential(accountName, accountKey);
string blobUri = "https://" + accountName + ".blob.core.windows.net";
blobServiceClient = new BlobServiceClient
(new Uri(blobUri), sharedKeyCredential);
}
You can also create a BlobServiceClient by using a connection string.
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
For information about how to obtain account keys and best practice guidelines for properly managing and safeguarding your keys, see Manage storage account access keys.
Important
The account access key should be used with caution. If your account access key is lost or accidentally placed in an insecure location, your service may become vulnerable. Anyone who has the access key is able to authorize requests against the storage account, and effectively has access to all the data. DefaultAzureCredential
provides enhanced security features and benefits and is the recommended approach for managing authorization to Azure services.
To learn more about each of these authorization mechanisms, see Authorize access to data in Azure Storage.
As you build apps to work with data resources in Azure Blob Storage, your code primarily interacts with three resource types: storage accounts, containers, and blobs. To learn more about these resource types, how they relate to one another, and how apps interact with resources, see Understand how apps interact with Blob Storage data resources.
The following guides show you how to access data and perform specific actions using the Azure Storage client library for .NET:
Guide | Description |
---|---|
Append data to blobs | Learn how to create an append blob and then append data to that blob. |
Configure a retry policy | Implement retry policies for client operations. |
Copy blobs | Copy a blob from one location to another. |
Create a container | Create containers. |
Create a user delegation SAS | Create a user delegation SAS for a container or blob. |
Create and manage blob leases | Establish and manage a lock on a blob. |
Create and manage container leases | Establish and manage a lock on a container. |
Delete and restore blobs | Delete blobs, and if soft-delete is enabled, restore deleted blobs. |
Delete and restore containers | Delete containers, and if soft-delete is enabled, restore deleted containers. |
Download blobs | Download blobs by using strings, streams, and file paths. |
Find blobs using tags | Set and retrieve tags, and use tags to find blobs. |
List blobs | List blobs in different ways. |
List containers | List containers in an account and the various options available to customize a listing. |
Manage properties and metadata | Get and set properties and metadata for blobs. |
Manage properties and metadata | Get and set properties and metadata for containers. |
Performance tuning for data transfers | Optimize performance for data transfer operations. |
Set or change a blob's access tier | Set or change the access tier for a block blob. |
Upload blobs | Learn how to upload blobs by using strings, streams, file paths, and other methods. |
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest Fabric, Power BI, and SQL learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayTraining
Module
Work with Azure Blob storage - Training
Learn how to use the Azure Blob storage client library to create and update Blob storage resources.
Certification
Microsoft Certified: Azure Developer Associate - Certifications
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.
Documentation
Create a blob container with .NET - Azure Storage
Learn how to create a blob container in your Azure Storage account using the .NET client library.
Quickstart: Azure Blob Storage library - .NET
In this quickstart, you learn how to use the Azure Blob Storage client library for .NET to create a container and a blob in Blob (object) storage. Next, you learn how to download the blob to your local computer, and how to list all of the blobs in a container.
Overview of the Azure Storage client libraries - Azure Storage
Overview of the Azure Storage client libraries. Learn about the management and data plane libraries, and when to use each set of libraries as you build your application.