您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Azure 存储 APIAzure Storage APIs for .NET

概述Overview

使用 Azure 存储在 .NET 应用程序中读取和写入文件、Blob(对象)数据、键值对和消息。Read and write files, blob (object) data, key-value pairs, and messages from your .NET applications with Azure Storage.

若要开始使用 Azure 存储,请参阅通过 .NET 开始使用 Azure Blob 存储To get started with Azure Storage, see Get started with Azure Blob storage using .NET.

客户端库Client library

使用连接字符串连接到 Azure 存储帐户,然后通过客户端库的类和方法来使用 Blob、表、文件或队列存储。Use connection strings to connect to an Azure Storage account, then use the client libraries' classes and methods to work with blob, table, file, or queue storage.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package WindowsAzure.Storage

.NET Core CLI.NET Core CLI

dotnet add package WindowsAzure.Storage

代码示例Code Example

此示例为现有存储帐户中的新容器创建新的 Blob。This example creates a new blob to a new container in an existing storage account.

/* Include these "using" directives...
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
*/

string storageConnectionString = "DefaultEndpointsProtocol=https;"
    + "AccountName=[Storage Account Name]"
    + ";AccountKey=[Storage Account Key]"
    + ";EndpointSuffix=core.windows.net";

CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient serviceClient = account.CreateCloudBlobClient();

// Create container. Name must be lower case.
Console.WriteLine("Creating container...");
var container = serviceClient.GetContainerReference("mycontainer");
container.CreateIfNotExistsAsync().Wait();

// write a blob to the container
CloudBlockBlob blob = container.GetBlockBlobReference("helloworld.txt");
blob.UploadTextAsync("Hello, World!").Wait();

管理 APIManagement APIs

使用管理 API 创建和管理 Azure 存储帐户与连接密钥。Create and manage Azure Storage accounts and connection keys with the management API.

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio package manager

Install-Package Microsoft.Azure.Management.Storage.Fluent

.NET Core CLI.NET Core CLI

dotnet add package Microsoft.Azure.Management.Storage.Fluent

代码示例Code Example

此示例创建存储帐户。This example creates a storage account.

/* Include this "using" directive...
using Microsoft.Azure.Management.Storage.Fluent
*/

IStorageAccount storage = azure.StorageAccounts.Define(storageAccountName)
    .WithRegion(Region.USEast)
    .WithNewResourceGroup(rgName)
    .Create();

示例Samples

查看 Azure 存储示例的完整列表View the complete list of Azure Storage samples.