Who's Bruno Willian

My photo
I'm Bruno, I've been working as a Dynamics CRM consultant since 2012. This blog is intended to share acknowledgement not only about Dynamics, but also any technology we use to extend the platform.

Tuesday, October 8, 2013

How to convert a List to XML

That is how to convert a List<T> to a XML

public string retrieveAccount()
{
    //Service
    IOrganizationService service = GetOrganization();

    //Retrieve Accounts
    Entity accounts = new Entity("account");

    EntityCollection accountList = methods.retriveAllAccounts(service);

    var xEle = new XElement("Accounts",
                    from account in accountList
                    select new XElement("Account",
                                new XAttribute("Name", account.Name),
                                new XAttribute("Telephone", account.Telephone),
                                new XAttribute("Celphone", account.Celphone),
                                new XAttribute("Email", account.Email),
                                new XAttribute("Address",account.Address),
                                new XAttribute("Number", account.Number),
                                new XAttribute("Location", account.Location)
                                ));

    return xEle.ToString();
}

No comments:

Post a Comment