locked
How do i get currently login user directory RRS feed

  • Question

  • Hello all,
    I am writing a windows application in C#. So far the paths to some files was written using relative path (based on current directory). Now, if we want to install this application and use we will have the following problem:
    Lets assume we installed in under "C:\program files\myapp" where myapp is my newly installed appliation. Now, when a user uses this application, its going to read/write data from "C\program files\myapp" directory. This is not a good thing to do and may even require administrative previlege (i think). Now i want to create a directory to read/write data within a user's directory that is usually created under "C:\users\userName". How do i get this directory in C# so that i could use it to put a users data there.

    Thanks,
    zolyit
    Thursday, August 6, 2009 12:13 AM

Answers

  • The particular folder you mention (c:\users\username) is Environment.GetEnvironmentVariable("USERPROFILE").

    You might also want to check out Environment.GetFolderPath which lets you get things like Desktop, My Documents, etc.
    • Marked as answer by Bsharper Thursday, August 6, 2009 4:27 AM
    Thursday, August 6, 2009 12:22 AM

All replies

  • The particular folder you mention (c:\users\username) is Environment.GetEnvironmentVariable("USERPROFILE").

    You might also want to check out Environment.GetFolderPath which lets you get things like Desktop, My Documents, etc.
    • Marked as answer by Bsharper Thursday, August 6, 2009 4:27 AM
    Thursday, August 6, 2009 12:22 AM
  • Thank you BinaryCoder, it helps alot!
    Thursday, August 6, 2009 4:27 AM