Alex Rivera | Logout

creating a new folder and a text file inside that folder

Asked 2010-11-22T10:29:46.183
20

I wanna create a new folder named log and inside that folder i want to create a textfile named log.txt and this is the path i want to create D:\New Folder

i have tried this to create a new folder named log

string FilePathSave = Folder.ToString() + System.IO.Directory.CreateDirectory(@"D:\New Folder\Log");

And i have created a text file using this

string FilePathSave = Folder.ToString() +"log.txt";
File.WriteAllText(FilePathSave, TextBox1.Text);                

But i cant create like D:\New Folder\Log\log.txt...any suggestion??

c#
Edit
Report

1 Answer

-1
string d = "D:\\New Folder";  

if (!Directory.Exists)  
  Directory.CreateDirectory(d);

File.WriteAllText(d + "\\log.txt", textBox1.Text);

And add the using System.IO directive to your form.

answered 2010-11-22T10:47:16.383

Your Answer