Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
May I know if anyone knows which interface could get host user name in WPF? For example: I creat a project and the item initialized with static string just like : C:\user\lcuser\xxx. But if I move this project in another PC with host-name called "mslcuser", I am sure this item will fail in initialization because the string have to be : C:\user\msuser\xxx. So how to get the host-name. Any suggestions will be greatly appreciated.
Posted
Updated 10-Apr-12 19:23pm
v2

That's not the "host name", but the "user name" - a big difference! The host name identifies the computer. Also, "C:\User" coukld be located elsewhere, and with Windows XP was also localised (e.g. C:\Dokumente und Einstellungen\Name\....).
What you need is the Environment.SpecialFolder enumeration, and you get the corresponding path by e.g. Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
 
Share this answer
 
Comments
Leon Lv 11-Apr-12 2:42am    
Great! Thanks for your solution. It gives me a great help.
I think for doing operations like you should use APP_DATA folder. This will appropriately take care of user/host names.

APP_DATA folder can be obtained by :
C#
Environment.GetFolderPath Method(...)

with ,ApplicationData' as first argument
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900