Thread: C# основной форум/C# work with Azure storage

C# work with Azure storage

Upload and Download Files in Azure Blob using C#







Re: C# work with Azure storage

Uploading and Downloading a Stream into an Azure Storage Blob


static void Main(string[] args)

{    

    var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));

    var myClient = storageAccount.CreateCloudBlobClient();

    var container = myClient.GetContainerReference("images-backup");

    container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);//lines modified

    var blockBlob = container.GetBlockBlobReference("mikepic.png");

      using (var fileStream = System.IO.File.OpenRead(@"c:\mikepic.png"))

      {

         blockBlob.UploadFromStream(fileStream);

      }

//lines modified

    Console.ReadLine();

}


Download a File

static void Main(string[] args)

{

    var storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnection"));

    var myClient = storageAccount.CreateCloudBlobClient();

    var container = myClient.GetContainerReference("images-backup");

    container.CreateIfNotExists(BlobContainerPublicAccessType.Blob);//lines modified

    var blockBlob = container.GetBlockBlobReference("mikepic.png");

    using (var fileStream = System.IO.File.OpenWrite(@"C:\Users\mbcrump\Downloads\mikepic-backup.png"))

   {

      blockBlob.DownloadToStream(fileStream);

   }

//lines modified


    Console.ReadLine();

}





Re: C# work with Azure storage

http://www.intstrings.com/ramivemula/articles/file-upload-and-download-to-azure-blob-storage/


Before we proceed to code, install “Windows Azure Storage” nuget (Right click Project –> Select “Manage Nuget Packages” –> Search for “Windows Azure Storage” –> Click Install –> Accept Terms and Conditions). This nuget package prepares our project for working seamlessly with Azure Storage (blobs, tables and queues).