a method to read a file from azure fileshare

Regarding the issue, please refer to the following code

 // read
            using (var stream = await file.OpenReadAsync().ConfigureAwait(false))
            using (var reader = new StreamReader(stream)) {
                // read csv file one line by line 
                while (!reader.EndOfStream) {
                  var line =await  reader.ReadLineAsync().ConfigureAwait(false);

            ShareFileProperties properties = await file.GetPropertiesAsync().ConfigureAwait(false);
            var myPosition = properties.ContentLength;
            var newData = "42,11,58, \"N\",85,12,45, \"W\", \"Worcester\", ND"+Environment.NewLine;
            var bytes = Encoding.UTF8.GetBytes(newData);
            await file.SetHttpHeadersAsync(myPosition + bytes.Length);
            using (var writer = await file.OpenWriteAsync(overwrite: false, position:(myPosition -1)).ConfigureAwait(false)) {
                await writer.WriteAsync(bytes, 0, bytes.Length);
                await writer.FlushAsync();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top