Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using(var upsProxy = new UserProfileService.UserProfileService())
  2. {
  3. upsProxy.Url = webUri + "/_vti_bin/UserProfileService.asmx";
  4. var schema = upsProxy.GetUserProfileSchema();
  5. var property = upsProxy.GetUserPropertyByAccountName(accountName, propertyName);
  6. var propertyInfo = schema.FirstOrDefault(pi => pi.Name == propertyName);
  7.  
  8. var termSetId = propertyInfo.TermSetId.Value;
  9. }
  10.  
  11. //1 Retrieve User Profile via SharePoint Web Services
  12. using(var upsProxy = new UserProfileService.UserProfileService())
  13. {
  14. upsProxy.Url = webUri + "/_vti_bin/UserProfileService.asmx";
  15. //upsProxy.CookieContainer = GetAuthCookies(webUri, userName, password);
  16.  
  17. var schema = upsProxy.GetUserProfileSchema();
  18. var property = upsProxy.GetUserPropertyByAccountName(accountName, propertyName);
  19. var propertyInfo = schema.FirstOrDefault(pi => pi.Name == propertyName);
  20.  
  21.  
  22. if (propertyInfo != null)
  23. {
  24. if (propertyInfo.TermSetId.HasValue && property.Values.Length > 0)
  25. {
  26. var termName = (string)property.Values[0].Value; //get first value
  27.  
  28. //2.Get Term via SharePoint CSOM
  29. using (var ctx = GetContext(webUri, userName, password))
  30. {
  31. var term = ResolveTerm(ctx, propertyInfo.TermSetId.Value, termName);
  32. }
  33.  
  34. }
  35. }
  36.  
  37. }
  38.  
  39.  
  40. public static Term ResolveTerm(ClientContext ctx,Guid termSetId,string termValue)
  41. {
  42. var ts = TaxonomySession.GetTaxonomySession(ctx);
  43. var termSet = ts.GetDefaultSiteCollectionTermStore().GetTermSet(termSetId);
  44. var term = termSet.Terms.GetByName(termValue);
  45. ctx.Load(term);
  46. ctx.ExecuteQuery();
  47. return term;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement