Azure blob.Download and upload using c#


#1

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?