使用 TFS 2012 API,如何获取用户的电子邮件地址?
我正在尝试使用 API 获取 TFS 2012 中特定用户的电子邮件地址.我已经在个人资料"部分设置了用户首选电子邮件地址.我在网上做了很多搜索,得到了以下代码.
I am trying to get the email address of a particular user in TFS 2012 using the API. I have set the users Preferred Email address in the Profile section. I have done plenty of searching online and have the following code.
var userId = "myUserId";
var collection = new TfsTeamProjectCollection(tfsUri, tfsCerd);
var managementService = collection.GetService<IIdentityManagementService>();
var member =
managementService
.ReadIdentity(
IdentitySearchFactor.AccountName,
userId,
MembershipQuery.Direct,
ReadIdentityOptions.ExtendedProperties);
var emailAddress = member.GetAttribute("Mail", null)
这段代码既成功又失败.成功检索到指定用户即为成功;但是,问题是 Email 属性为空.当我分析成员变量时,我注意到Mail"属性列在那里并且是空的.然后我注意到还有另外两个名为ConfirmedNotificationAddress"和CustomNotificationAddress"的属性,它们正确地包含了我的首选电子邮件地址.
This code is both a success and a failure. It is a success in that it successfully retrieves the specified user; however, the problem is that the Email attribute is blank. When I analyzed the member variable, I noticed the "Mail" attribute was listed there and it was empty. I then noticed there were two other attributes called "ConfirmedNotificationAddress" and "CustomNotificationAddress" that had my preferred email address correctly in there.
我想知道为什么我似乎无法使用首选电子邮件地址正确加载Mail"变量,因为我需要此代码才能在很多人的服务器上工作.
I am wondering why I can't seem to get the "Mail" variable to load properly with the preferred email address as I will need this code to work on a lot of peoples servers.
尝试使用 Mail
而不是 Email
作为属性名称 - 这对我有用.
Try using Mail
instead of Email
for the attribute name - that works for me.
此外,如果这不起作用,请检查 member.GetProperties()
的结果 - 也许这会给您正确的名称.
Also, if that doesn't work, check the results of member.GetProperties()
- maybe that will give you the right name to use.
对我来说,GetProperty("Mail")
也有效.