Skip to content

JerryPei1997/storage-blobs-dotnet-quickstart

 
 

Repository files navigation

page_type languages products description
sample
csharp
azure
azure-storage
dotnet-core
A simple sample project to help you get started using Azure Storage with .NET Core and C# as the development language.

Azure SDK Versions

To use the latest Azure SDK version storage-blobs-dotnet-quickstart-v3, please add the following dependency:

For the previous Azure SDK version storage-blobs-dotnet-quickstart-v12, please add the following dependency:

Prerequisites

To complete this tutorial:

If you don't have an Azure subscription, create a free account before you begin.

Create a Storage Account using the Azure Portal

Step 1 : Create a new general-purpose Storage Account to use for this tutorial.

  • Go to the Azure Portal and log in using your Azure account.
  • Select New > Storage > Storage account.
  • Select your Subscription.
  • For Resource group, create a new one and give it a unique name.
  • Enter a name for your storage Account.
  • Select the Location to use for your Storage Account.
  • Set Account kind to StorageV2(general purpose v2).
  • Set Performance to Standard.
  • Set Replication to Locally-redundant storage (LRS).
  • Set Secure transfer required to Disabled.
  • Check Review + create and click Create to create your Storage Account.

Step 2 : Copy and save Connection string.

After your Storage Account is created. Click on it to open it. Select Settings > Access keys > Key1/key, copy the associated Connection string to the clipboard, then paste it into a text editor for later use.

Put the connection string in an environment variable

This solution requires a connection string be stored in an environment variable securely on the machine running the sample. Follow one of the examples below depending on your operating system to create the environment variable. If using Windows close your open IDE or shell and restart it to be able to read the environment variable.

Linux

export AZURE_STORAGE_CONNECTIONSTRING="<yourconnectionstring>"

Windows

setx AZURE_STORAGE_CONNECTIONSTRING "<yourconnectionstring>"

At this point, you can run this application. It creates its own file to upload and download, and then cleans up after itself by deleting everything at the end.

Run the application

First, clone the repository on your machine:

git clone https://github.com/Azure-Samples/storage-blobs-dotnet-quickstart.git

Then, switch to the appropriate folder:

Navigate to your directory where the project file (.csproj) resides and run the application with the dotnet run command.

dotnet run

This Quickstart shows how to do following operations of Storage Blobs.

  • Create a Storage Account using the Azure Portal.
  • Create a container.
  • Upload a file to block blob.
  • List blobs.
  • Download a blob to file.
  • Delete a blob.
  • Delete the container.

More information

The Azure Storage documentation includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

About

Code for QuickStart article for accessing Blobs with .NET

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%