More in this section

Forums / Developing with Sitefinity / How do i retrieve all user profiles

How do i retrieve all user profiles

10 posts, 0 answered
  1. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    15 Apr 2009
    Link to this post
    How will I be able to retrieve all of the user profiles. I tried to use the ProfileManager.GetAllProfiles but it always throws error "object reference not set to instance of object"?I'm using the sitefinity as my defaultprovider
  2. Sonya
    Sonya avatar
    231 posts
    Registered:
    24 Sep 2012
    17 Apr 2009
    Link to this post
    Hi Roland,

    I have run the following code in Users.aspx.cs (~/Sitefinity/Admin/CmsAdmin/Users.aspx.cs) and it has run successfully:
    using System.Web.Profile; 
     
    ... 
     
    ProfileInfoCollection profileInfo = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All); 
    int profileCount = profileInfo.Count; 

    Let us know if you need further help.

    Kind regards,
    Sonya
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    17 Apr 2009
    Link to this post
    Hi Sonya,

    Thanks for the trial but for sure Users.aspx will work as it is built in with sitefinity. My point is I am trying to implement it on my custom controls and it is not working. I always get the object reference not set to instance error. Thanks
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Apr 2009
    Link to this post
    Hello Roland,

    I checked the code and it works fine at my end.

    Here are another two samples that shows how to retrieve profile data.

    Using ProfileManager.GetAllProfiles();

    <%@ Page Language="C#" %> 
    <%@ Import Namespace="System.Web.Profile" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <script runat="server"
     
    public void Page_Load() 
       
      GetProfiles(); 
     
    private void GetProfiles() 
       ProfileInfoCollection coll = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.Authenticated); 
       ProfileGrid.DataSource = coll
       ProfileGrid.DataBind(); 
     
    </script> 
    <html  > 
    <head> 
    <title>Sample: Find Profiles</title> 
    </head> 
    <body> 
     
    <form id="form1" runat="server"
      <h3>Profile List</h3> 
     
      <asp:Label id="TotalLabel" runat="server" text="0" /> Profiles found.<br /> 
     
      <asp:GridView id="ProfileGrid" runat="server" 
                    CellPadding="2" CellSpacing="1" Gridlines="Both"
        <HeaderStyle BackColor="darkblue" ForeColor="white" /> 
      </asp:GridView> 
     
    </form> 
     
    </body> 
    </html> 

    And another example that we use MembershipUserCollection

    MembershipUserCollection collection = Membership.GetAllUsers(); 
            foreach (MembershipUser member in collection) 
            { 
     
                ProfileBase profile = ProfileBase.Create(member.ToString()); 
                Response.Write(profile.GetPropertyValue("FirstName") + "<br />" + profile.GetPropertyValue("LastName")); 
     
     
            } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    17 Apr 2009
    Link to this post
    May I know how many users were currently created on your test site? I also tested it with just single user which is my own account first and then it work but when I added a new user the the problem already persists.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    17 Apr 2009
    Link to this post
    Hello Roland,

    I have got 12. Debug the code and see what happens. The code sample uses ASP.NET classes.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    17 Apr 2009
    Link to this post
    Hi Ivan,

    I tried to use the Membership that you suggested and it works great. Many thanks for that. 

    I would like to follow up this time the problem I keep on getting with the Telerik.Security.WebControls.ManagerProfile control. On edit mode, I successfully populated all the fields within the control successfully. However when I change the value in it and tried to update the entries I always got an error on the ManageProfile.SetProfileProperties(username) saying something about "invalid cast" where I double checked that the username I pass to it is correctly. Can you guide me of the correct way of using the ManageProfile on Edit mode? Thanks
  8. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    20 Apr 2009
    Link to this post
    Hi Roland,

    Can you please post the exception and the stack trace?

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  9. Roland
    Roland avatar
    45 posts
    Registered:
    23 Feb 2009
    20 Apr 2009
    Link to this post
    Hi Ivan,
    I already got it working. The problem is I don't have permissions to edit other users profile so I have to inherit the adminpage in order for me to be able to edit other users.

    Thanks for the help on membershipcollection it greatly solves my first problem.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    21 Apr 2009
    Link to this post
    Hello Roland,

    Let us know if you get stuck anywhere.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
10 posts, 0 answered