Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: Get name of system folder [using C#] Pin
Luc Pattyn7-May-11 5:30
sitebuilderLuc Pattyn7-May-11 5:30 
GeneralRe: Get name of system folder [using C#] Pin
shivamkalra7-May-11 6:20
shivamkalra7-May-11 6:20 
AnswerRe: Get name of system folder [using C#] Pin
Luc Pattyn7-May-11 6:45
sitebuilderLuc Pattyn7-May-11 6:45 
GeneralRe: Get name of system folder [using C#] Pin
shivamkalra7-May-11 6:58
shivamkalra7-May-11 6:58 
GeneralRe: Get name of system folder [using C#] Pin
Luc Pattyn7-May-11 7:10
sitebuilderLuc Pattyn7-May-11 7:10 
GeneralRe: Get name of system folder [using C#] Pin
shivamkalra7-May-11 17:30
shivamkalra7-May-11 17:30 
AnswerRe: Get name of system folder [using C#] Pin
DaveyM696-May-11 20:52
professionalDaveyM696-May-11 20:52 
AnswerRe: Get name of system folder [using C#] Pin
DaveyM696-May-11 21:25
professionalDaveyM696-May-11 21:25 
Having seen Dave's answer that it is available in v4, I've had a look at how it's done using reflector and these two functions combined perform the same task and will work with earlier .NET versions so long as it's run on a platform that supports it - if not, a PlatformNotSupportedException will be raised.
C#
public const int UserProfile = 40;

[DllImport("shfolder.dll", CharSet = CharSet.Auto)]
private static extern int SHGetFolderPath(IntPtr hwndOwner, int nFolder, IntPtr hToken, int dwFlags, StringBuilder lpszPath);

public static string GetUserPath()
{
    StringBuilder resultBuilder = new StringBuilder(260);
    int num = SHGetFolderPath(IntPtr.Zero, UserProfile, IntPtr.Zero, 0, resultBuilder);
    if (num == -2146233031)
        throw new PlatformNotSupportedException();
    return resultBuilder.ToString();
}

Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)



QuestionCan't publish a project even though no build errors Pin
Nathan D Cook6-May-11 9:31
Nathan D Cook6-May-11 9:31 
AnswerRe: Can't publish a project even though no build errors Pin
AspDotNetDev6-May-11 9:39
protectorAspDotNetDev6-May-11 9:39 
Questionpass a Size object to sendmessage Pin
manchukuo6-May-11 7:37
manchukuo6-May-11 7:37 
AnswerRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 8:05
professionalDaveyM696-May-11 8:05 
GeneralRe: pass a Size object to sendmessage Pin
manchukuo6-May-11 8:12
manchukuo6-May-11 8:12 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 8:27
professionalDaveyM696-May-11 8:27 
GeneralRe: pass a Size object to sendmessage [modified] Pin
manchukuo6-May-11 8:30
manchukuo6-May-11 8:30 
GeneralRe: pass a Size object to sendmessage [modified] Pin
DaveyM696-May-11 9:26
professionalDaveyM696-May-11 9:26 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 10:13
professionalDaveyM696-May-11 10:13 
GeneralRe: pass a Size object to sendmessage Pin
DaveyM696-May-11 11:11
professionalDaveyM696-May-11 11:11 
GeneralRe: pass a Size object to sendmessage Pin
manchukuo6-May-11 11:14
manchukuo6-May-11 11:14 
QuestionRandom numbers [modified] Pin
meet_ssr6-May-11 2:46
meet_ssr6-May-11 2:46 
AnswerRe: Random numbers Pin
PIEBALDconsult6-May-11 2:52
mvePIEBALDconsult6-May-11 2:52 
GeneralRe: Random numbers PinPopular
David19876-May-11 2:56
David19876-May-11 2:56 
AnswerRe: Random numbers Pin
Luc Pattyn6-May-11 3:06
sitebuilderLuc Pattyn6-May-11 3:06 
GeneralRe: Random numbers PinPopular
David19876-May-11 3:45
David19876-May-11 3:45 
AnswerRe: Random numbers Pin
Luc Pattyn6-May-11 3:52
sitebuilderLuc Pattyn6-May-11 3:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.