• 0

Environment.SpecialFolder.Personal (C#) & CSIDL_PERSONAL (C++) Problem


Question

So I redirected My Documents folder in Win 7. To D:\.

Now I want to get the My Documents folder in a C# app and in the C++ game, I want to get the same file in the same My Documents folder. So I'm doing this:

C++:

  SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_DEFAULT, path);

And I get: path = "C:\Users\DAaaMan64\Documents"

C#:

string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

And I get: path = "D:\\"

^^ that is the redirected My Documents folder.

As far as I'm concerned this is a bug.

I'm about ready to just pipe it to the child process. Anyone got an ideas?

Thanks.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
Have you tried asking for SHGFP_TYPE_CURRENT instead? At the moment you appear to be asking for the default location, rather than the current one.

That was a the solution. Thank you :)

Link to comment
Share on other sites

  • 0

Also notice that Environment.GetFolderPath() does a P/Invoke to SHGetFolderPath with the TYPE flag always set to SHGFP_TYPE_CURRENT (0).

post-51387-1261412193.png

Further, the SHGetFolderPath function has been replaced by SHGetKnownFolderPath, which allows an expanded set of options.

Glad things are working.

Link to comment
Share on other sites

  • 0
Further, the SHGetFolderPath function has been replaced by SHGetKnownFolderPath, which allows an expanded set of options.

The only problem with that is that it's new in Vista, meaning you'll have to check the OS version and then conditionally call either it or SHGetFolderPath depending on the version. Normally not worth it.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.