0
votes

I have deployed a asp mvc where I am trying to display csv files as tables which have been stored in Azure blob storage.

I have problems to read the files in a blob container. I couldn't find any solution in the Microsoft documentation.

My blob containers are public and maybe I could access through their url, but I dont know how to read the csv files. Any Ideas?

1
Your question is not relevant to a Webjob. A Webjob is usually used for background processes. Your real problem is that you can't display a CSV file that's stored in a blob.lopezbertoni
@lopezbertoni My aim is to visualize real time data that comes into the blob storage.auenal
Understood. A webjob is not going to help you visualize data. You can use it to process the data if needed.lopezbertoni
@lopezbertoni Is there an alternative way to visualize the data? I imagined something like this: docs.microsoft.com/en-us/azure/iot-hub/…auenal
Any updates? Do you solve the problem?Fei Han

1 Answers

1
votes

My blob containers are public and maybe I could access through their url, but I dont know how to read the csv files. Any Ideas?

To read the csv file stored in Azure Blob storage, you could refer to the following sample code.

CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connection string");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");    
CloudBlockBlob blockBlobReference = container.GetBlockBlobReference("testdata.csv");


using (var reader = new StreamReader(blockBlobReference.OpenRead()))
{
    string row = "";

    while (!reader.EndOfStream)
    {
        //read data from csv file

        row = reader.ReadLine(); 
    }
}

My aim is to visualize real time data that comes into the blob storage.

It seems that you’d like to real-time display csv data as tables in clients’ web page. ASP.NET SignalR could help us develop real-time web functionality easily, you could detect csv file under a specified Blob container and call hub method to read data from csv file and push data to connected clients in your WebJob function, and then you could update UI based on the pushed csv data on SignalR client side.

call hub method inside your WebJob function

var hub = new HubConnection("http://xxx/signalr/hubs");

var proxy = hub.CreateHubProxy("HubName");
hub.Start().Wait();

//invoke hub method
proxy.Invoke("PushData", "filename");

hub method to push data to connected clients

public void PushData(string filename)
{
   //read data from csv file (blob)

   //call javascript side function to populate (or update) tables with csv data  

   Clients.All.UpdateTables(data);
}