Click here to Skip to main content
15,899,937 members
Home / Discussions / C#
   

C#

 
GeneralRe: [DllImport("NetApi32.dll"... throws exception for first few times Pin
shoab.shah27-Feb-13 1:10
shoab.shah27-Feb-13 1:10 
GeneralRe: [DllImport("NetApi32.dll"... throws exception for first few times Pin
Dave Kreskowiak27-Feb-13 1:19
mveDave Kreskowiak27-Feb-13 1:19 
GeneralRe: [DllImport("NetApi32.dll"... throws exception for first few times Pin
shoab.shah27-Feb-13 19:07
shoab.shah27-Feb-13 19:07 
GeneralRe: [DllImport("NetApi32.dll"... throws exception for first few times Pin
Dave Kreskowiak28-Feb-13 1:29
mveDave Kreskowiak28-Feb-13 1:29 
QuestionC# datetime compared to sql server datetime Pin
classy_dog26-Feb-13 18:45
classy_dog26-Feb-13 18:45 
AnswerRe: C# datetime compared to sql server datetime Pin
Pete O'Hanlon26-Feb-13 19:36
mvePete O'Hanlon26-Feb-13 19:36 
AnswerRe: C# datetime compared to sql server datetime Pin
Mangal Deep Gupta26-Feb-13 23:11
Mangal Deep Gupta26-Feb-13 23:11 
GeneralRe: C# datetime compared to sql server datetime PinPopular
Pete O'Hanlon27-Feb-13 0:07
mvePete O'Hanlon27-Feb-13 0:07 
GeneralRe: C# datetime compared to sql server datetime Pin
classy_dog27-Feb-13 2:04
classy_dog27-Feb-13 2:04 
GeneralRe: C# datetime compared to sql server datetime Pin
Pete O'Hanlon27-Feb-13 2:13
mvePete O'Hanlon27-Feb-13 2:13 
GeneralRe: C# datetime compared to sql server datetime Pin
classy_dog27-Feb-13 3:56
classy_dog27-Feb-13 3:56 
GeneralRe: C# datetime compared to sql server datetime Pin
Pete O'Hanlon27-Feb-13 4:12
mvePete O'Hanlon27-Feb-13 4:12 
GeneralRe: C# datetime compared to sql server datetime Pin
Matt T Heffron27-Feb-13 10:07
professionalMatt T Heffron27-Feb-13 10:07 
GeneralRe: C# datetime compared to sql server datetime Pin
PIEBALDconsult27-Feb-13 3:31
mvePIEBALDconsult27-Feb-13 3:31 
SuggestionRe: C# datetime compared to sql server datetime Pin
Matt T Heffron27-Feb-13 9:58
professionalMatt T Heffron27-Feb-13 9:58 
AnswerRe: C# datetime compared to sql server datetime Pin
jschell28-Feb-13 10:08
jschell28-Feb-13 10:08 
QuestionList view Question Pin
Member 979920426-Feb-13 14:57
Member 979920426-Feb-13 14:57 
AnswerRe: List view Question Pin
Richard MacCutchan26-Feb-13 22:31
mveRichard MacCutchan26-Feb-13 22:31 
AnswerRe: List view Question Pin
Amir Mohammad Nasrollahi29-Jul-13 21:29
professionalAmir Mohammad Nasrollahi29-Jul-13 21:29 
QuestionHow do I populate child elements in XML? Pin
Magela26-Feb-13 12:56
Magela26-Feb-13 12:56 
AnswerRe: How do I populate child elements in XML? Pin
Mangal Deep Gupta26-Feb-13 23:24
Mangal Deep Gupta26-Feb-13 23:24 
GeneralRe: How do I populate child elements in XML? Pin
Magela27-Feb-13 4:26
Magela27-Feb-13 4:26 
AnswerRe: How do I populate child elements in XML? Pin
Jegan Thiyagesan27-Feb-13 4:31
Jegan Thiyagesan27-Feb-13 4:31 
Hi,
When it come to xml serialization and deserialization, I would always use them as objects.

C#
using System;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;

namespace Test
{
    [Serializable]
    [XmlRoot("RootElement")]
    public class RootElement
    {
        [XmlElement]
        public int Id { get; set; }
        public string Name { get; set; }
        public Address Address_1 { get; set; }
        public Address Address_2 { get; set; }
    }

    public class Address
    {
        [XmlElement]
        public string Number {get; set;}
        public string Street { get; set; }
        public string Town { get; set; }
    }

    public class Test2
    {
        Address address_1 = new Address()
        {
            Number = "123",
            Street = "My Road",
            Town = "My Home Town"
        };

        Address address_2 = new Address()
        {
            Number = "PO BOX 456",
            Street = "My Street",
            Town = "My Birth Town"
        };

        public void setXmlValues()
        {
            RootElement testOut = new RootElement {
                                                    Id = 1,
                                                    Name = "Customer Name",
                                                    Address_1 = address_1,
                                                    Address_2 = address_2
                                                    };

            xml_serialise(testOut);

            RootElement testIn = xml_deserialise();
            int id = testIn.Id;
            string Name = testIn.Name;
            string myBirthTown = testIn.Address_2.Town;

        }


        private void xml_serialise(RootElement test)
        {
            XmlSerializer ser = new XmlSerializer(typeof(RootElement));


            using (TextWriter writer = new StreamWriter("test.xml"))
            {
                ser.Serialize(writer, test);
            }
        }

        private RootElement xml_deserialise()
        {
            XmlSerializer ser = new XmlSerializer(typeof(RootElement));

            RootElement test;

            using (TextReader writer = new StreamReader("test.xml"))
            {
                test = (RootElement)ser.Deserialize(writer);
            }

            return test;
        }
    }
}


I hope this helps.

Regards
Jegan
Think! Don't write a line of code unless you absolutely need to.

GeneralRe: How do I populate child elements in XML? Pin
Magela27-Feb-13 4:38
Magela27-Feb-13 4:38 
QuestionOffice Development problems Pin
Daytona67526-Feb-13 11:32
Daytona67526-Feb-13 11:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.