How can I write an empty file to Azure Storage File Share

Peter Ma 216 Reputation points Microsoft Employee
2021-07-22T03:57:13.437+00:00

I read an empty file from blob storage and get an empty stream.
But when I try to write the stream to File Share, it tells me:

Azure.Core: Specified argument was out of the range of valid values. (Parameter 'length').

Here are the codes(code works fine for non-empty files):

ShareDirectoryClient directory = shareClient.GetDirectoryClient(targetFolder);
ShareFileClient targetFile = directory.GetFileClient(targetFileName);

using (Stream fileStream = new MemoryStream())
{
await blobDownloadInfo.Content.CopyToAsync(fileStream);
fileStream.Position = 0;
targetFile.Create(fileStream.Length);
targetFile.Upload(fileStream);
}

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,420 questions
{count} votes

Accepted answer
  1. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2021-07-27T22:50:18.697+00:00

    anonymous user-0048
    I spoke with our SDK service team and they advised there should be no issue creating an empty file in Azure Files. They pointed to the examples located on GitHub. If you feel there is some error or bug I recommend opening an issue directly with the SDK team.


    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.