Y
Yosh
What is the best method to obtain the actual folder path to My Documents for
the current logged in user in C#?
Thanks,
Yosh
the current logged in user in C#?
Thanks,
Yosh
Gabriel Lozano-Morán said:1)
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.StringBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
Yosh said:What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?
Thanks,
Yosh
Yosh said:Is one method better than the other?
Do they both always return the My Documents path or is there a situation
in which one wouldn't?
Thanks,
Yosh
Gabriel Lozano-Morán said:1)
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder,
IntPtr hToken, int dwFlags, System.Text.StringBuilder lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
Yosh said:What is the best method to obtain the actual folder path to My Documents
for the current logged in user in C#?
Thanks,
Yosh
Gabriel Lozano-Morán said:I posted the two ways to let you know why I love .NET, you would offcourse
go for number 1
Gabriel Lozano-Morán
Yosh said:Is one method better than the other?
Do they both always return the My Documents path or is there a situation
in which one wouldn't?
Thanks,
Yosh
Gabriel Lozano-Morán said:1)
Environment.GetFolderPath(Environment.SpecialFolder.Personal)
2)
Or the extreme way what is actually done by the GetFolderPath method but
with less checking
[DllImport("shfolder.dll", CharSet=CharSet.Auto)]
internal static extern int SHGetFolderPath(IntPtr hwndOwner, int
nFolder, IntPtr hToken, int dwFlags, System.Text.StringBuilder
lpszPath);
[STAThread]
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
SHGetFolderPath(IntPtr.Zero, 5, IntPtr.Zero, 0, sb);
Console.WriteLine(sb);
Console.Read();
}
Gabriel Lozano-Morán
What is the best method to obtain the actual folder path to My
Documents for the current logged in user in C#?
Thanks,
Yosh