Using absolute path with streamwriter C#

absolute-path, c#, streamwriter

Solution

You should use `Environment.GetFolderPath` - which in this case would avoid you hard-coding `My Documents` at all:

string docs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

If you wanted to get a directory name relative to that, you should use `Path.Combine`:

string fooDocsDirectory = Path.Combine(docs, "foo");

Problem

I am trying to use streamwriter to create a text file in the my documents folder, however it thinks i am using a relative path when i am actually using a full path. I am trying to create the file using this path: "%HOMEPATH%/My Documents/", but it treats this as a relative path. Any help would be appreciated, thanks.

Original source