tags:

views:

1196

answers:

1

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
Yes I know about the Directory.CreateDirectory but to CreateDirectory you can only pass a string. I need to pass a FileStream
theKing
Arif, how do you expect to create a directory based on the *contents* of a file?
Rob Kennedy
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
You mean, you want to use what's in a FileStream as the name of a folder?
Chris Hynes
Correct, if it was possible
theKing
but what's in a FileStream is the contents of a file?
Svish
Maybe it just has the name of the directory to create?
Chris Hynes