C# code read a csv content from blob

Rajnilari2015
Posted by Rajnilari2015 under Azure category on | Points: 40 | Views : 5215
The below code will do so

public string GetBlobData(string filename, string connectionString, string containerName)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference(containerName);

// Retrieve reference to a blob named "test.csv"
CloudBlockBlob blockBlob2 = container.GetBlockBlobReference(filename);

string text;
using (var memoryStream = new MemoryStream())
{
blockBlob2.DownloadToStream(memoryStream);
text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
}

return text;
}

Comments or Responses

Login to post response