none
How to download a file from cloud and to get the path in C# RRS feed

  • Question

  • using System;
    using System.Collections.Generic;
    using System.IO;
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Auth;
    using Microsoft.WindowsAzure.Storage.Blob;
    using System.Xml;
    using Newtonsoft.Json;
    namespace download
    {

    class Program
    {
    public static object KnownFolders { get; private set; }
    static void Main(string[] args)
    {
    const string StorageAccountName = “”;
    const string StorageAccountKey = “”;

    //get reference to storage account
    Console.WriteLine(@“Connecting to storage account”);
    var storageAccount = new CloudStorageAccount(
    new StorageCredentials(StorageAccountName, StorageAccountKey), true);

    var blobClient = storageAccount.CreateCloudBlobClient();

    //get reference to container
    Console.WriteLine(@“Getting reference to container”);
    var container = blobClient.GetContainerReference(“sample”);
    // var container1 = blobClient.GetContainerReference(“Processed”);

    //get ref to blob
    //CloudBlockBlob block_Blob = container.GetBlockBlobReference(“student.xml”);

    //List the blob
    var blobs = container.ListBlobs();
    DownloadBlobs(blobs);

    Console.WriteLine(“Completed”);
    Console.ReadLine();
    }
    private static void DownloadBlobs(IEnumerable blobs)
    {
    foreach (var blob in blobs)
    {
    if (blob is CloudBlockBlob block_Blob)
    {
    block_Blob.DownloadToFile(block_Blob.Name, mode: FileMode.Create);
    Console.WriteLine(block_Blob);

    XmlDocument doc = new XmlDocument();
    doc.Load(block_Blob.Name);
    string jsonText = JsonConvert.SerializeXmlNode(doc);
    Console.WriteLine(jsonText);

    //write string to file
    System.IO.File.WriteAllText(“C:\Users\T430\source\repos\download\download\bin\student.json”, jsonText);

    //upload files

    }
    }
    }
    }
    }

    I want to upload the file back to blob to different folder.How can i do this?

    Is there any way to read the file in azure blob and save in an another folder without downlaoding it?


    • Edited by ShreeKSD Saturday, March 17, 2018 7:54 PM
    • Moved by Stanly Fan Monday, March 19, 2018 2:19 AM c# related
    • Moved by Fei Hu Thursday, March 22, 2018 7:56 AM Moved From C#
    Saturday, March 17, 2018 12:24 PM

All replies

  • using System;
    using System.Collections.Generic;
    using System.IO;
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Auth;
    using Microsoft.WindowsAzure.Storage.Blob;
    using System.Xml;
    using Newtonsoft.Json;
    namespace download
    {

    class Program
    {
    public static object KnownFolders { get; private set; }
    static void Main(string[] args)
    {
    const string StorageAccountName = “”;
    const string StorageAccountKey = “”;

    //get reference to storage account
    Console.WriteLine(@“Connecting to storage account”);
    var storageAccount = new CloudStorageAccount(
    new StorageCredentials(StorageAccountName, StorageAccountKey), true);

    var blobClient = storageAccount.CreateCloudBlobClient();

    //get reference to container
    Console.WriteLine(@“Getting reference to container”);
    var container = blobClient.GetContainerReference(“sample”);
    // var container1 = blobClient.GetContainerReference(“Processed”);

    //get ref to blob
    //CloudBlockBlob block_Blob = container.GetBlockBlobReference(“student.xml”);

    //List the blob
    var blobs = container.ListBlobs();
    DownloadBlobs(blobs);

    Console.WriteLine(“Completed”);
    Console.ReadLine();
    }
    private static void DownloadBlobs(IEnumerable blobs)
    {
    foreach (var blob in blobs)
    {
    if (blob is CloudBlockBlob block_Blob)
    {
    block_Blob.DownloadToFile(block_Blob.Name, mode: FileMode.Create);
    Console.WriteLine(block_Blob);

    XmlDocument doc = new XmlDocument();
    doc.Load(block_Blob.Name);
    string jsonText = JsonConvert.SerializeXmlNode(doc);
    Console.WriteLine(jsonText);

    //write string to file
    System.IO.File.WriteAllText(“C:\Users\T430\source\repos\download\download\bin\student.json”, jsonText);

    //upload files

    }
    }
    }
    }
    }

    I want to upload the file back to blob to different folder.How can i do this?

    Is there any way to read the file in azure blob and save in an another folder without downlaoding it?

    Saturday, March 17, 2018 7:54 PM
  • Hello ShreeKSD,

    According to your question is more related to Microsoft azure, you could consult experience people for better support.

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.cloudstorageaccount?view=azure-dotnet

    If you have some grammar or code errors in using C#, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 22, 2018 7:56 AM