Is it possible to create a directory using StreamWriter?
+15
A:
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());
Chris Hynes
2009-02-09 22:10:40
Yes I know about the Directory.CreateDirectory but to CreateDirectory you can only pass a string. I need to pass a FileStream
theKing
2009-02-09 22:35:00
Arif, how do you expect to create a directory based on the *contents* of a file?
Rob Kennedy
2009-02-09 22:59:51
Sorry I am not clear about your question? I never said I am not expecting to a create a directory based on the *contents* of a file. Please clarify
theKing
2009-02-10 18:48:47
You mean, you want to use what's in a FileStream as the name of a folder?
Chris Hynes
2009-02-11 00:22:49
Correct, if it was possible
theKing
2009-02-13 19:23:19
but what's in a FileStream is the contents of a file?
Svish
2009-02-17 22:16:41
Maybe it just has the name of the directory to create?
Chris Hynes
2009-02-19 13:15:44