Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using(var upsProxy = new UserProfileService.UserProfileService())
- {
- upsProxy.Url = webUri + "/_vti_bin/UserProfileService.asmx";
- var schema = upsProxy.GetUserProfileSchema();
- var property = upsProxy.GetUserPropertyByAccountName(accountName, propertyName);
- var propertyInfo = schema.FirstOrDefault(pi => pi.Name == propertyName);
- var termSetId = propertyInfo.TermSetId.Value;
- }
- //1 Retrieve User Profile via SharePoint Web Services
- using(var upsProxy = new UserProfileService.UserProfileService())
- {
- upsProxy.Url = webUri + "/_vti_bin/UserProfileService.asmx";
- //upsProxy.CookieContainer = GetAuthCookies(webUri, userName, password);
- var schema = upsProxy.GetUserProfileSchema();
- var property = upsProxy.GetUserPropertyByAccountName(accountName, propertyName);
- var propertyInfo = schema.FirstOrDefault(pi => pi.Name == propertyName);
- if (propertyInfo != null)
- {
- if (propertyInfo.TermSetId.HasValue && property.Values.Length > 0)
- {
- var termName = (string)property.Values[0].Value; //get first value
- //2.Get Term via SharePoint CSOM
- using (var ctx = GetContext(webUri, userName, password))
- {
- var term = ResolveTerm(ctx, propertyInfo.TermSetId.Value, termName);
- }
- }
- }
- }
- public static Term ResolveTerm(ClientContext ctx,Guid termSetId,string termValue)
- {
- var ts = TaxonomySession.GetTaxonomySession(ctx);
- var termSet = ts.GetDefaultSiteCollectionTermStore().GetTermSet(termSetId);
- var term = termSet.Terms.GetByName(termValue);
- ctx.Load(term);
- ctx.ExecuteQuery();
- return term;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement