Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF file interface
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 10-Apr-12 19:17pm
Leon Lv363
Edited 10-Apr-12 19:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)
Leon Lv at 11-Apr-12 2:42am
Great! Thanks for your solution. It gives me a great help.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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 :
 Environment.GetFolderPath Method(...)
with ,ApplicationData' as first argument

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

  Print Answers RSS
0 OriginalGriff 230
1 Sergey Alexandrovich Kryukov 104
2 Richard MacCutchan 100
3 kbrandwijk 75
4 Vinay Mistry 70
0 Sergey Alexandrovich Kryukov 9,040
1 OriginalGriff 8,121
2 CPallini 2,613
3 Richard MacCutchan 2,221
4 Abhinav S 1,928

Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 11 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100