I'm creating a method to append new text to an existing file in an Azure File Share. This is the code:
public async Task AppendAllTextAsync(string path, string text)
{
var fileClient = _fileShare.GetRootDirectoryClient().GetFileClient(path);
var currentFileLength = fileClient.GetProperties().Value.ContentLength;
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(text)))
{
await fileClient.CreateAsync(currentFileLength + ms.Length);
await fileClient.UploadRangeAsync(new HttpRange(currentFileLength - 1, ms.Length), ms);
}
}
When I test with a sample txt file whose initial content is this:

it removes all the content and append the content at the end.
For example, if I call my method like this on the said file
accessor.AppendAllText("Sample file.txt", " 2");
So it's like removing all the previous content when offsetting.
Any ideas on why it's happening or a way of doing this correctly?
