Shared Documents Folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there an elegant way to reference the "shared documents" folder without
hard-coding "C:\Documents and Settings\All Users\Documents"?
Environment.GetFolderPath() doesn't have any document folders! Thanks.
 
Sorry, I didn't noticed you wanted "All Users". I don't see a SpecialFolder
constant that would return the "All Users" documents, but you can do some
string manipulation or P/Invoke SHGetSpecialFolderPath.

using System.Runtime.InteropServices;
using System.Text;

// ...

[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out]
StringBuilder lpszPath, int nFolder, bool fCreate);
const int CSIDL_COMMON_DOCUMENTS = 0x002e;

// ...

StringBuilder temp = new StringBuilder(255);
SHGetSpecialFolderPath(IntPtr.Zero, temp, CSIDL_COMMON_DOCUMENTS, false);
string commonDocuments = temp.ToString();
 
mfdatsw1 said:
Is there an elegant way to reference the "shared documents" folder without
hard-coding "C:\Documents and Settings\All Users\Documents"?
Environment.GetFolderPath() doesn't have any document folders! Thanks.
 
Back
Top