Click here to Skip to main content
12,065,756 members (35,009 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: WPF file
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 20:17pm
Leon Lv363
Edited 10-Apr-12 20:23pm
v2
Rate this: bad
 
good
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)
  Permalink  
Comments
Leon Lv 11-Apr-12 2:42am
   
Great! Thanks for your solution. It gives me a great help.
Rate this: bad
 
good
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
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160207.1 | Last Updated 11 Apr 2012
Copyright © CodeProject, 1999-2016
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