Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > How do i get currently login user directory
 

How do i get currently login user directory

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
zolyita  Thursday, August 06, 2009 12:13 AM
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 byzolyita Thursday, August 06, 2009 4:27 AM
  •  
BinaryCoder  Thursday, August 06, 2009 12:22 AM
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 byzolyita Thursday, August 06, 2009 4:27 AM
  •  
BinaryCoder  Thursday, August 06, 2009 12:22 AM
Thank you BinaryCoder, it helps alot!
zolyita  Thursday, August 06, 2009 4:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Problems with the Data Source Configuration Wizard in Visual C++ 2008 Express Edition
• repeater for winforms
• Insert Master-Details at once...
• Need to enter string into currency formatted DGV column
• bind combobox in datagridview in win app .net 2008
• DataGridViewComboBox column problem
• Datagridview SelectionChanged Event
• How to avoid dragging a form
• Combobox Usage VS2003 -> VS2005
• CheckBox box = (CheckBox)sender