Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File does not contain a definition for "WriteAllTextAsync"?

I'm following Microsoft's quick-start guide on how to use Azure Blobs and inside there is a specific section where you go to create a sample text file to upload. However, I'm not sure what is wrong since this code segment produces an error which says File does not contain a definiton for "WriteAllTextAsync":

// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "quickstart" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);

// Write text to the file
await File.WriteAllTextAsync(localFilePath, "Hello, World!");

// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);

Console.WriteLine("Uploading to Blob storage as blob:\n\t {0}\n", blobClient.Uri);

// Open the file and upload its data
using FileStream uploadFileStream = File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();

Does anyone know why this is happening? I have imported all the correct NuGet and such but I can't seem to figure it out since this is directly their code.

like image 772
DoubleJumper222 Avatar asked Nov 04 '25 03:11

DoubleJumper222


1 Answers

I would recommend to check what version of framework/net core you use. According to this ms doc

File.WriteAllTextAsync Method Applies to:

.NET

5.0 Preview 7

.NET Core

3.1 3.0 2.2 2.1 2.0

.NET Standard

2.1

like image 67
Vladimir Avatar answered Nov 06 '25 17:11

Vladimir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!