Create a folder and write a file to it

I would  like to write  the file that I am testing to the c:\data\In-string.txt

Using:
objStreamWriter = System.IO.File.CreateText("In-string.txt")
WDJ98338Asked:
Who is Participating?
 
udhayakumardConnect With a Mentor Commented:
              if (!Directory.Exists)
                    Directory.CreateDirectory("C:\\data");

                File.AppendAllText("c:\\data\\In-string.txt", "Content of the file");
0
 
WDJ98338Author Commented:
Thanks for your help with this.
0
 
udhayakumardConnect With a Mentor Commented:
if u want to use StreamWriter

                 if (!Directory.Exists)
                    Directory.CreateDirectory("C:\\data");

                 StreamWriter objStreamWriter = File.CreateText("c:\\data\\In-string.txt");

                 objStreamWriter.Write("Content of file");

                 objStreamWriter.Close();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.