locked
List with user data from User Profile Service RRS feed

  • Question

  • Hi there!

    I got SP intranet site up and running with more then 2000+ users on it.
    User Profile Services is getting users attributes from Active Directory.

    How can i make a list with all of those users and columns like Department, Manager, Office number, etc.. 

    After that i'm going to apply a filter by current user department.

    I would really appreciate some offer.
    Thanks!




    Thursday, January 23, 2014 1:25 PM

Answers

  • There is a sharepoint hidden list called User Information List , if you want to filter by current user department I recommend that you use ser search API and search People using SourceID 

     public static ResultTable SearchUsers(string query,int limit,string [] selectproperties)
            {
                KeywordQuery kq = new KeywordQuery(SPContext.Current.Site);
                //select properties
                foreach (string property in selectproperties)
                {
                    kq.SelectProperties.Add(property);
                    
                }
                       
                kq.SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
                kq.QueryText = query;
                kq.RowLimit = limit;
                ResultTableCollection results = new SearchExecutor().ExecuteQuery(kq);
                return results.Filter("TableType", KnownTableTypes.RelevantResults).FirstOrDefault<ResultTable>();
    
            }

    you need to pass the query Department:CurrentUserDepartment and to get current user department 

      UserProfileManager manager = new UserProfileManager(SPServiceContext.GetContext(SPContext.Current.Site));
                        UserProfile currentUser = manager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
    string department=currentUser["Department"].toString();



    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

    Monday, January 27, 2014 7:15 AM
  • Thank you very much Amr.
    I wish i were so good at coding as you are :)

    I already find another way to fulfill my needs.
    I created enterprise search center for people search, made some templates i needed and i think it will serve me even better.

    Anyway, thank you again!
    Monday, January 27, 2014 2:15 PM

All replies

  • There is a sharepoint hidden list called User Information List , if you want to filter by current user department I recommend that you use ser search API and search People using SourceID 

     public static ResultTable SearchUsers(string query,int limit,string [] selectproperties)
            {
                KeywordQuery kq = new KeywordQuery(SPContext.Current.Site);
                //select properties
                foreach (string property in selectproperties)
                {
                    kq.SelectProperties.Add(property);
                    
                }
                       
                kq.SourceId = new Guid("B09A7990-05EA-4AF9-81EF-EDFAB16C4E31");
                kq.QueryText = query;
                kq.RowLimit = limit;
                ResultTableCollection results = new SearchExecutor().ExecuteQuery(kq);
                return results.Filter("TableType", KnownTableTypes.RelevantResults).FirstOrDefault<ResultTable>();
    
            }

    you need to pass the query Department:CurrentUserDepartment and to get current user department 

      UserProfileManager manager = new UserProfileManager(SPServiceContext.GetContext(SPContext.Current.Site));
                        UserProfile currentUser = manager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
    string department=currentUser["Department"].toString();



    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

    Monday, January 27, 2014 7:15 AM
  • Thank you very much Amr.
    I wish i were so good at coding as you are :)

    I already find another way to fulfill my needs.
    I created enterprise search center for people search, made some templates i needed and i think it will serve me even better.

    Anyway, thank you again!
    Monday, January 27, 2014 2:15 PM