Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a directory using StreamWriter?

Tags:

c#

.net

Is it possible to create a directory using StreamWriter?

like image 658
theKing Avatar asked Feb 09 '09 22:02

theKing


1 Answers

No. You can't actually create a directory using a StreamWriter. Use Directory.CreateDirectory instead.

If you're trying to read the directory name out of a file stream and then create a file based on that text, you'll need something like this:

FileStream fs; // this is the filestream from somewhere. make sure to dispose it
using (StreamReader r = new StreamReader(fs))
    Directory.CreateDirectory(r.ReadToEnd());
like image 92
Chris Hynes Avatar answered Sep 20 '22 12:09

Chris Hynes