How to Write a string to a Text File in C# ?

Published on June 26, 2014 by abundantcode

Filed under C#

Last modified June 26, 2014

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3758 times

Below is a sample code snippet that demonstrates how to write a string to a text file in C# .

How to Write a string to a Text File in C# ?

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.IO;
namespace AbundantcodeConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
           string ACFile = @"E:\input.txt";
           using (System.IO.StreamWriter writer = File.CreateText(ACFile))
           {
               writer.WriteLine("Welcome to Abundantcode.com");
           }
           Console.ReadLine();
        }     
    }
    
}

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to read file contents from command line in Windows 10 ?

You can use the command "type" in the command line to read the contents of the text file i...

How to Copy the entire contents of a directory in C# ?

Below is a sample code snippets that demonstrates how to copy the entire contents of a directory to ...

How to replace a File extension in C# ?

If you want to replace a file extension in C# , you can use the ChangeExtension method defined in th...