適用於 .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 套件管理員主控台安裝 NuGet 套件,或使用 .NET Core CLIInstall 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 套件管理員主控台安裝 NuGet 套件,或使用 .NET Core CLIInstall 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.