Reputation: 1636
Is it possible to create a directory using StreamWriter?
Upvotes: 20
Views: 17436
Reputation: 10239
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());
Upvotes: 25