Beginner .Net Course: How to Add Text to a File

How to add text to a file in a single line?

File.AppendAllText(@"c:\path\file.txt", "text content" + Environment.NewLine);

And there you go! No need to open a StreamWriter in C# and all the rest, this works in a single line.

See Microsoft doc: https://docs.microsoft.com/fr-fr/dotnet/api/system.io.file.appendalltext

Join the conversation

You need an account to comment on this article. Creating one is free and takes under a minute.

  • The XMLTV file, free to download every day
  • Comment on articles and reply to other readers
  • Get an e-mail when an article you follow is updated

No comments yet.

Une erreur s'est produite. Cette application peut ne plus répondre jusqu'à ce qu'elle soit rechargée.Veuillez contacter l'auteur. Reload 🗙