Created
January 16, 2022 18:04
-
-
Save RachidAZ/66e4ed3c443b0dcc169e1f3cfd81e8ef to your computer and use it in GitHub Desktop.
read azure blob as stream
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Azure.Storage.Blobs; | |
using System.IO; | |
static internal MemoryStream GetBlobStream(string connectionString, string blobContainer, string blobName) | |
{ | |
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); | |
BlobClient blobClient = new BlobClient(connectionString, blobContainer, blobName); | |
var memoryStream = new MemoryStream(); | |
blobClient.DownloadTo(memoryStream); | |
return memoryStream; | |
} | |
static internal List<string> ParseFileStream(MemoryStream memoryStream, string fileName) | |
{ | |
string[] fileNameSplit = fileName.Split("."); | |
string fileType = fileNameSplit[fileNameSplit.Length-1]; | |
if (fileType.ToUpper().Equals("CSV")) | |
{ | |
memoryStream.Seek(0, SeekOrigin.Begin); | |
TextFieldParser parser = new TextFieldParser(memoryStream); | |
parser.TextFieldType = FieldType.Delimited; | |
parser.SetDelimiters(","); | |
// get header: | |
string[] header = parser.ReadFields(); | |
while (!parser.EndOfData) | |
{ | |
// handle the file lines here | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment