Azure storage not finding csv file












1














I am trying to read a csv file from my azure storage account.
To convert each line into an object and build a list of those objects.
It keeps erring, and the reason is it cant find the file (Blob not found). The file is there, It is a csv file.



File in azure storage



Error:




StorageException: The specified blob does not exist.
BatlGroup.Site.Services.AzureStorageService.AzureFileMethods.ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName) in AzureFileMethods.cs
+
await blob.DownloadToStreamAsync(memoryStream);




 public async Task<Stream> ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName)
{
// Retrieve reference to a blob (fileName)
var blob = container.GetBlockBlobReference(fileName);

using (var memoryStream = new MemoryStream())
{
//downloads blob's content to a stream
await blob.DownloadToStreamAsync(memoryStream);
return memoryStream;

}

}


I've made sure the file is public. I can download any text file that is stored there, but none of the csv files.



I am also not sure what format to take it in as I need to iterate through the lines.



I see examples of bringing the whole file down to a temp drive and working with it there but that seems unproductive as then I could just store the file in wwroot folder instead of azure.



What is the most appropriate way to read a csv file from azure storage.










share|improve this question
























  • The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
    – juunas
    Nov 19 '18 at 13:43










  • The file path is correct, which is why I can read the text files.
    – dinotom
    Nov 19 '18 at 14:03










  • That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
    – juunas
    Nov 19 '18 at 14:08










  • @juunas...and its not just that file, I can download all the txt files but none of the csv files
    – dinotom
    Nov 19 '18 at 14:15






  • 1




    “l” is lowercase when you’re passing in method while the blob name has it in uppercase.
    – Gaurav Mantri
    Nov 19 '18 at 16:16
















1














I am trying to read a csv file from my azure storage account.
To convert each line into an object and build a list of those objects.
It keeps erring, and the reason is it cant find the file (Blob not found). The file is there, It is a csv file.



File in azure storage



Error:




StorageException: The specified blob does not exist.
BatlGroup.Site.Services.AzureStorageService.AzureFileMethods.ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName) in AzureFileMethods.cs
+
await blob.DownloadToStreamAsync(memoryStream);




 public async Task<Stream> ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName)
{
// Retrieve reference to a blob (fileName)
var blob = container.GetBlockBlobReference(fileName);

using (var memoryStream = new MemoryStream())
{
//downloads blob's content to a stream
await blob.DownloadToStreamAsync(memoryStream);
return memoryStream;

}

}


I've made sure the file is public. I can download any text file that is stored there, but none of the csv files.



I am also not sure what format to take it in as I need to iterate through the lines.



I see examples of bringing the whole file down to a temp drive and working with it there but that seems unproductive as then I could just store the file in wwroot folder instead of azure.



What is the most appropriate way to read a csv file from azure storage.










share|improve this question
























  • The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
    – juunas
    Nov 19 '18 at 13:43










  • The file path is correct, which is why I can read the text files.
    – dinotom
    Nov 19 '18 at 14:03










  • That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
    – juunas
    Nov 19 '18 at 14:08










  • @juunas...and its not just that file, I can download all the txt files but none of the csv files
    – dinotom
    Nov 19 '18 at 14:15






  • 1




    “l” is lowercase when you’re passing in method while the blob name has it in uppercase.
    – Gaurav Mantri
    Nov 19 '18 at 16:16














1












1








1







I am trying to read a csv file from my azure storage account.
To convert each line into an object and build a list of those objects.
It keeps erring, and the reason is it cant find the file (Blob not found). The file is there, It is a csv file.



File in azure storage



Error:




StorageException: The specified blob does not exist.
BatlGroup.Site.Services.AzureStorageService.AzureFileMethods.ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName) in AzureFileMethods.cs
+
await blob.DownloadToStreamAsync(memoryStream);




 public async Task<Stream> ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName)
{
// Retrieve reference to a blob (fileName)
var blob = container.GetBlockBlobReference(fileName);

using (var memoryStream = new MemoryStream())
{
//downloads blob's content to a stream
await blob.DownloadToStreamAsync(memoryStream);
return memoryStream;

}

}


I've made sure the file is public. I can download any text file that is stored there, but none of the csv files.



I am also not sure what format to take it in as I need to iterate through the lines.



I see examples of bringing the whole file down to a temp drive and working with it there but that seems unproductive as then I could just store the file in wwroot folder instead of azure.



What is the most appropriate way to read a csv file from azure storage.










share|improve this question















I am trying to read a csv file from my azure storage account.
To convert each line into an object and build a list of those objects.
It keeps erring, and the reason is it cant find the file (Blob not found). The file is there, It is a csv file.



File in azure storage



Error:




StorageException: The specified blob does not exist.
BatlGroup.Site.Services.AzureStorageService.AzureFileMethods.ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName) in AzureFileMethods.cs
+
await blob.DownloadToStreamAsync(memoryStream);




 public async Task<Stream> ReadCsvFileFromBlobAsync(CloudBlobContainer container, string fileName)
{
// Retrieve reference to a blob (fileName)
var blob = container.GetBlockBlobReference(fileName);

using (var memoryStream = new MemoryStream())
{
//downloads blob's content to a stream
await blob.DownloadToStreamAsync(memoryStream);
return memoryStream;

}

}


I've made sure the file is public. I can download any text file that is stored there, but none of the csv files.



I am also not sure what format to take it in as I need to iterate through the lines.



I see examples of bringing the whole file down to a temp drive and working with it there but that seems unproductive as then I could just store the file in wwroot folder instead of azure.



What is the most appropriate way to read a csv file from azure storage.







c# azure csv azure-storage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:33

























asked Nov 19 '18 at 12:59









dinotom

2,28453887




2,28453887












  • The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
    – juunas
    Nov 19 '18 at 13:43










  • The file path is correct, which is why I can read the text files.
    – dinotom
    Nov 19 '18 at 14:03










  • That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
    – juunas
    Nov 19 '18 at 14:08










  • @juunas...and its not just that file, I can download all the txt files but none of the csv files
    – dinotom
    Nov 19 '18 at 14:15






  • 1




    “l” is lowercase when you’re passing in method while the blob name has it in uppercase.
    – Gaurav Mantri
    Nov 19 '18 at 16:16


















  • The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
    – juunas
    Nov 19 '18 at 13:43










  • The file path is correct, which is why I can read the text files.
    – dinotom
    Nov 19 '18 at 14:03










  • That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
    – juunas
    Nov 19 '18 at 14:08










  • @juunas...and its not just that file, I can download all the txt files but none of the csv files
    – dinotom
    Nov 19 '18 at 14:15






  • 1




    “l” is lowercase when you’re passing in method while the blob name has it in uppercase.
    – Gaurav Mantri
    Nov 19 '18 at 16:16
















The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
– juunas
Nov 19 '18 at 13:43




The most probable reason is that your path is wrong. If the file is in a virtual folder, you need to include the folder(s) into the file name, e.g. "folder/subfolder/file.jpg"
– juunas
Nov 19 '18 at 13:43












The file path is correct, which is why I can read the text files.
– dinotom
Nov 19 '18 at 14:03




The file path is correct, which is why I can read the text files.
– dinotom
Nov 19 '18 at 14:03












That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
– juunas
Nov 19 '18 at 14:08




That's extremely odd then, because the content type shouldn't affect your ability to download it.. It's just metadata.
– juunas
Nov 19 '18 at 14:08












@juunas...and its not just that file, I can download all the txt files but none of the csv files
– dinotom
Nov 19 '18 at 14:15




@juunas...and its not just that file, I can download all the txt files but none of the csv files
– dinotom
Nov 19 '18 at 14:15




1




1




“l” is lowercase when you’re passing in method while the blob name has it in uppercase.
– Gaurav Mantri
Nov 19 '18 at 16:16




“l” is lowercase when you’re passing in method while the blob name has it in uppercase.
– Gaurav Mantri
Nov 19 '18 at 16:16












1 Answer
1






active

oldest

votes


















0














Regarding how to iterate through the lines, after you get the memory stream, you can use StreamReader to read them line by line.



Sample code as below:



using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using System;
using System.IO;

namespace ConsoleApp17
{
class Program
{
static void Main(string args)
{
string connstr = "your connection string";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connstr);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("t11");
CloudBlockBlob blockBlob = container.GetBlockBlobReference("students.csv");
string text="";
string temp = "";
using (var memoryStream = new MemoryStream())
{
blockBlob.DownloadToStream(memoryStream);

//remember set the position to 0
memoryStream.Position = 0;
using (var reader = new StreamReader(memoryStream))
{
//read the csv file as per line.
while (!reader.EndOfStream && !string.IsNullOrEmpty(temp=reader.ReadLine()))
{
text = text + "***" + temp;
}

}


}

Console.WriteLine(text);
Console.WriteLine("-------");
Console.ReadLine();
}
}
}


My csv file:
enter image description here



The test result:
enter image description here






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375193%2fazure-storage-not-finding-csv-file%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Regarding how to iterate through the lines, after you get the memory stream, you can use StreamReader to read them line by line.



    Sample code as below:



    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Blob;
    using System;
    using System.IO;

    namespace ConsoleApp17
    {
    class Program
    {
    static void Main(string args)
    {
    string connstr = "your connection string";
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connstr);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference("t11");
    CloudBlockBlob blockBlob = container.GetBlockBlobReference("students.csv");
    string text="";
    string temp = "";
    using (var memoryStream = new MemoryStream())
    {
    blockBlob.DownloadToStream(memoryStream);

    //remember set the position to 0
    memoryStream.Position = 0;
    using (var reader = new StreamReader(memoryStream))
    {
    //read the csv file as per line.
    while (!reader.EndOfStream && !string.IsNullOrEmpty(temp=reader.ReadLine()))
    {
    text = text + "***" + temp;
    }

    }


    }

    Console.WriteLine(text);
    Console.WriteLine("-------");
    Console.ReadLine();
    }
    }
    }


    My csv file:
    enter image description here



    The test result:
    enter image description here






    share|improve this answer


























      0














      Regarding how to iterate through the lines, after you get the memory stream, you can use StreamReader to read them line by line.



      Sample code as below:



      using Microsoft.WindowsAzure.Storage;
      using Microsoft.WindowsAzure.Storage.Blob;
      using System;
      using System.IO;

      namespace ConsoleApp17
      {
      class Program
      {
      static void Main(string args)
      {
      string connstr = "your connection string";
      CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connstr);
      CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
      CloudBlobContainer container = blobClient.GetContainerReference("t11");
      CloudBlockBlob blockBlob = container.GetBlockBlobReference("students.csv");
      string text="";
      string temp = "";
      using (var memoryStream = new MemoryStream())
      {
      blockBlob.DownloadToStream(memoryStream);

      //remember set the position to 0
      memoryStream.Position = 0;
      using (var reader = new StreamReader(memoryStream))
      {
      //read the csv file as per line.
      while (!reader.EndOfStream && !string.IsNullOrEmpty(temp=reader.ReadLine()))
      {
      text = text + "***" + temp;
      }

      }


      }

      Console.WriteLine(text);
      Console.WriteLine("-------");
      Console.ReadLine();
      }
      }
      }


      My csv file:
      enter image description here



      The test result:
      enter image description here






      share|improve this answer
























        0












        0








        0






        Regarding how to iterate through the lines, after you get the memory stream, you can use StreamReader to read them line by line.



        Sample code as below:



        using Microsoft.WindowsAzure.Storage;
        using Microsoft.WindowsAzure.Storage.Blob;
        using System;
        using System.IO;

        namespace ConsoleApp17
        {
        class Program
        {
        static void Main(string args)
        {
        string connstr = "your connection string";
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connstr);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("t11");
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("students.csv");
        string text="";
        string temp = "";
        using (var memoryStream = new MemoryStream())
        {
        blockBlob.DownloadToStream(memoryStream);

        //remember set the position to 0
        memoryStream.Position = 0;
        using (var reader = new StreamReader(memoryStream))
        {
        //read the csv file as per line.
        while (!reader.EndOfStream && !string.IsNullOrEmpty(temp=reader.ReadLine()))
        {
        text = text + "***" + temp;
        }

        }


        }

        Console.WriteLine(text);
        Console.WriteLine("-------");
        Console.ReadLine();
        }
        }
        }


        My csv file:
        enter image description here



        The test result:
        enter image description here






        share|improve this answer












        Regarding how to iterate through the lines, after you get the memory stream, you can use StreamReader to read them line by line.



        Sample code as below:



        using Microsoft.WindowsAzure.Storage;
        using Microsoft.WindowsAzure.Storage.Blob;
        using System;
        using System.IO;

        namespace ConsoleApp17
        {
        class Program
        {
        static void Main(string args)
        {
        string connstr = "your connection string";
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connstr);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference("t11");
        CloudBlockBlob blockBlob = container.GetBlockBlobReference("students.csv");
        string text="";
        string temp = "";
        using (var memoryStream = new MemoryStream())
        {
        blockBlob.DownloadToStream(memoryStream);

        //remember set the position to 0
        memoryStream.Position = 0;
        using (var reader = new StreamReader(memoryStream))
        {
        //read the csv file as per line.
        while (!reader.EndOfStream && !string.IsNullOrEmpty(temp=reader.ReadLine()))
        {
        text = text + "***" + temp;
        }

        }


        }

        Console.WriteLine(text);
        Console.WriteLine("-------");
        Console.ReadLine();
        }
        }
        }


        My csv file:
        enter image description here



        The test result:
        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 3:17









        Ivan Yang

        2,134125




        2,134125






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375193%2fazure-storage-not-finding-csv-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]