Copied to clipboard

Flag this post as spam?

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


  • Fredrik Esseen 594 posts 830 karma points
    Jan 12, 2010 @ 15:24
    Fredrik Esseen
    0

    Exporting members to XML

    Is there some simple way to export members to XML?

     

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jan 12, 2010 @ 15:49
    Dirk De Grave
    0

    hmm, not really, as the member info is scattered across some db tables, but you could build a nice sql query and use the for xml clause to return info from the db (if you're using sql server, not sure if other db flavors support this...). I may have some code laying around, will check if I can find it.

     

    Cheers,

    /Dirk

  • Petr Snobelt 923 posts 1534 karma points
    Jan 12, 2010 @ 16:41
    Petr Snobelt
    2

    or use search (for all), copy result to excel and save as xml

     

    Petr

  • Fredrik Esseen 594 posts 830 karma points
    Jan 13, 2010 @ 10:30
    Fredrik Esseen
    0

    I solved but I suppose this is not the most effective way to do it.

    In this solution I get alla members and prints their LoginName as excel

     

    string sqlstr = "SELECT * FROM CMSMEMBER";

     

    IRecordsReader reader = umbraco.BusinessLogic.Application.SqlHelper.ExecuteReader(sqlstr);

     

     

    XmlDocument doc = new XmlDocument();

     

    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

    doc.AppendChild(dec);

     

    XmlElement root = doc.CreateElement("Members");

    doc.AppendChild(root);

     

     

    while (reader.Read())

    {

     

     

    Member TheMember = Member.GetMemberFromEmail(reader.GetString("EMAIL"));

     

     

    if (Member.GetMemberFromEmail(reader.GetString("EMAIL")) != null)

    {

     

    XmlElement MemberNode = doc.CreateElement("Member");

     

    XmlElement NameNode = doc.CreateElement("Name");

     

     

    NameNode.InnerText = TheMember.LoginName;

     

    MemberNode.AppendChild(NameNode);

     

    }

    }

     

    doc.Save(Server.MapPath(

    "Members.xml"));

     

    Response.ContentType =

    "application/vnd.ms-excel";

    Response.Charset =

    "iso-8859-1";

    Response.ContentEncoding = System.Text.

    Encoding.GetEncoding("ISO-8859-1");

     

    Response.AddHeader(

    "Content-Disposition", "attachment;filename=" + "Members" + ".xls");

     

    this.EnableViewState = false;

    System.IO.

    StringWriter tw = new System.IO.StringWriter();

    System.Web.UI.

    HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

     

    DataGrid dgrid = new DataGrid();

     

    DataSet ds = new DataSet();

    ds.ReadXml(Server.MapPath(

    "Members.xml"));

    dgrid.DataSource = ds;

    dgrid.DataBind();

     

    dgrid.RenderControl(hw);

     

    Response.Write(tw.ToString());

     

    Response.Flush();

    Response.End();

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies