Getting a random UserProfile In SharePoint 2010 -


i trying retrieve random number of users userprofilemanager.

but encountering errors when deploying live servers. can't seem see causing error. code below:

for (int = 0; < numberofuserlimit; i++)             {                 userprofile = profilemanager.getuserprofile(random.next(1, numberofuserlimit));                  if (up["firstname"] != null && up["firstname"].value != null && !string.isnullorempty(up["firstname"].value.tostring()))                 {                     datarow druserprofile;                      druserprofile = dtuserprofile.newrow();                      druserprofile["displayname"] = up.displayname;                     druserprofile["firstname"] = up["firstname"].value;                     druserprofile["lastname"] = up["lastname"].value;                     druserprofile["department"] = up["department"].value;                     druserprofile["location"] = up["sps-location"].value;                     druserprofile["hiredate"] = up["sps-hiredate"].value;                     druserprofile["contactnumber"] = up["office"].value;                      if (up["pictureurl"] != null && up["pictureurl"].value != null && !string.isnullorempty(up["pictureurl"].value.tostring()))                     {                         string cleanaccountname = up["accountname"].value.tostring().replace(@"\", "_");                         string pictureurl = string.format("https://my.someintranet.com/user photos/profile pictures/{0}_mthumb.jpg", cleanaccountname);                          druserprofile["image"] = pictureurl;                     }                     else                     {                         druserprofile["image"] = "~/_layouts/images/o14_person_placeholder_96.png";                     }                      druserprofile["mysiteurl"] = up.publicurl;                      dtuserprofile.rows.add(druserprofile);                 }             } 

my code works when apply simple foreach code above instead of "for loop":

    foreach (userprofile in profilemanager) 

which proves can return userprofiles.

any appreciated.

code handles random better

public class testclass {    private random = new random();    private long totalnumberofprofiles;   //profilemanager.count not returns count correctly     public testclass()    {       //this not have in constructor point have cached (reasonably)       ienumerator profiles = profilemanager.getenumerator();        long counter = 0;       while (profiles.movenext())          counter++;       this.totalnumberofprofiles = counter;    }      public fillindataset()    {       //something here...       ienumerator profiles = profilemanager.getenumerator();        int index = random.next(1, totalnumberofprofiles);        while (index >= 0 && profiles.movenext())          index--;         userprofile currentprofile = (userprofile)profiles.current        //something here...     } } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -