Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jeffrey Valeroso 40 posts 101 karma points
    Aug 08, 2012 @ 15:07
    Jeffrey Valeroso
    0

    How to populate all Members with Profile properties?

    HI, Im trying to populate all members with profile properties, athough I have successfully done this but It's loading too slow.

     

      public static XPathNodeIterator GetAllMembers()

            {

                XmlDocument membersXML = new XmlDocument();

                membersXML.LoadXml("<members></members>");

     

                try

                {

     

     

                    //For each member in a specific member group

                    foreach (Member memb in Member.GetAll)

                    {

     

                                           //The current member object - get the XML

     

                            //New XMLNode for <member>

                            XmlNode membNode = membersXML.CreateElement("member");

     

                            //memberID attribute

                            XmlAttribute membAttrID = membersXML.CreateAttribute("memberID");

                            membAttrID.Value = memb.Id.ToString();

                            membNode.Attributes.Append(membAttrID);

     

                            foreach (Property prop in memb.getProperties)

                            {

                                //Property node

                                XmlNode propNode = membersXML.CreateElement(prop.PropertyType.Alias);

     

                                //Set the value

                                propNode.InnerText = prop.Value.ToString();

     

                                //Append Property node to member node

                                membNode.AppendChild(propNode);

                            }

     

                            //Append to <members> root node

                            membersXML.SelectSingleNode("/members").AppendChild(membNode);

     

     

                    }

     

                    return membersXML.CreateNavigator().Select("//members");

                }

                catch (Exception ex)

                {

                    membersXML.LoadXml("<response><success>false</success><error>" + ex.Message.ToString() + "</error></response>");

                    return membersXML.CreateNavigator().Select("/response");

                }

            }

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Aug 10, 2012 @ 00:42
    Bo Damgaard Mortensen
    1

    Hi Jeffrey,

    When I'm iterating through members I'm using the uQuery extension "GetMembersByXPath(string xpath)" from uComponents. This loads the members from the XML cache instead of loading them from the database by calling Member.GetAll. Should increase performance a lot by doing it this way :-)

    Grab uComponents here: uComponents

    The reference you need are uComponents.Core and you're good to go!

    The XPath code would then look something like this:

    var members = uQuery.GetMembersByXPath("//*");

    Where "members" is your collection of members that you can loop through.

    Let me know if there's any hold-ups :-)

    All the best,

    Bo

Please Sign in or register to post replies

Write your reply to:

Draft