Get user information in Windows 8?

2019-08-03 18:52发布

问题:

I have created a sample in Windows 8 using C# and XAML to get user info of my system which includes Name, Email Id, Photo of my User Login. I am able to get Name and image but I am not able to get Email Id. My system is logged in by my hotmail id. Following is the code: how can I achieve to get email id?

string displayName = await UserInformation.GetDisplayNameAsync();
string Emailid = await UserInformation.GetPrincipalNameAsync();
StorageFile image = UserInformation.GetAccountPicture(AccountPictureKind.LargeImage) as StorageFile;

In Email id I am getting blank. How to fix it?

回答1:

@seshuk had given you the correct answer, from the MSDN documentation

Only domain users have a principal name. Access to the principal name can be blocked by privacy settings (for example, if the UserInformation::NameAccessAllowed property is false). If access is blocked, this method returns an empty string.

This method requires the enterpriseAuthentication capability.

A Hotmail id, by definition, would not be a domain user. Additionally, you'd need a company account to publish such an app, since it requires the enterprise authentication capability.