Click here to Skip to main content
15,887,027 members
Home / Discussions / C#
   

C#

 
AnswerRe: Document opening/saving idiom Pin
PIEBALDconsult27-Apr-12 3:22
mvePIEBALDconsult27-Apr-12 3:22 
AnswerRe: Document opening/saving idiom Pin
Eddy Vluggen27-Apr-12 7:04
professionalEddy Vluggen27-Apr-12 7:04 
AnswerRe: Document opening/saving idiom Pin
OriginalGriff27-Apr-12 9:29
mveOriginalGriff27-Apr-12 9:29 
NewsExpand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 0:10
nqs_vn27-Apr-12 0:10 
AnswerRe: Expand the text in the RichTextBox. Pin
VJ Reddy27-Apr-12 1:16
VJ Reddy27-Apr-12 1:16 
GeneralRe: Expand the text in the RichTextBox. Pin
nqs_vn27-Apr-12 16:40
nqs_vn27-Apr-12 16:40 
QuestionSave List with BinaryReader Pin
larsp77726-Apr-12 23:22
larsp77726-Apr-12 23:22 
AnswerRe: Save List with BinaryReader Pin
Wayne Gaylard26-Apr-12 23:44
professionalWayne Gaylard26-Apr-12 23:44 
Fisrt off, you should easily be able to serialise a List with XMLSerializer, you just need to ensure that Your custom class is marked with the XmlRoot attribute, and you create a class that inherits from List that holds your collection, something like this

C#
[XmlRoot("Persons")]
public class People : List<Person>
{

}

[XmlRoot("Person")]
public class Person
{
    public Person()
    {
    }

    public Person(string name)
    {
        Name = name;
    }

    [XmlElement("Name")]
    public string Name { get; set; }

}


then you can use this
C#
using (StringWriter writer = new StringWriter())
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Persons));
                XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                namespaces.Add(string.Empty, string.Empty);
                XmlWriter xmlWriter = XmlWriter.Create(writer, settings);
                serializer.Serialize(xmlWriter, personList, namespaces);
            }

or something to that effect, and this should work to serialize to XML.

If you still want to serialize to a binary file, you should use a BinaryFormatter like this
C#
using (Stream stream = File.Open("people.bin", FileMode.Create))
            {
                BinaryFormatter bin = new BinaryFormatter();
                bin.Serialize(stream, People);
            }

and deserialise also using a BinaryFormatter
C#
using (Stream stream = File.Open("people.bin", FileMode.Open))
            {
                BinaryFormatter bin = new BinaryFormatter();
                var people = (List<Person>)bin.Deserialize(stream);
            }


Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

QuestionWindow Service didn’t run when SQL Server is on Remote Database Pin
masterprogrammertech26-Apr-12 23:17
masterprogrammertech26-Apr-12 23:17 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
PIEBALDconsult27-Apr-12 3:24
mvePIEBALDconsult27-Apr-12 3:24 
AnswerRe: Window Service didn’t run when SQL Server is on Remote Database Pin
charlybones7-May-12 22:17
charlybones7-May-12 22:17 
Questionimpresiones en c# Pin
samuelalvarito26-Apr-12 6:42
samuelalvarito26-Apr-12 6:42 
AnswerRe: impresiones en c# Pin
phil.o26-Apr-12 6:48
professionalphil.o26-Apr-12 6:48 
AnswerRe: impresiones en c# Pin
Abhinav S26-Apr-12 7:02
Abhinav S26-Apr-12 7:02 
AnswerRe: impresiones en c# Pin
jschell28-Apr-12 7:44
jschell28-Apr-12 7:44 
Questionspooler en c# Pin
samuelalvarito26-Apr-12 6:40
samuelalvarito26-Apr-12 6:40 
Questioncomo usar el evento drag&drop para cargar documentos office en un formulario de c# Pin
samuelalvarito26-Apr-12 6:39
samuelalvarito26-Apr-12 6:39 
AnswerRe: como usar el evento drag&drop para cargar documentos office en un formulario de c# Pin
Abhinav S26-Apr-12 6:45
Abhinav S26-Apr-12 6:45 
AnswerRe: como usar el evento drag&drop para cargar documentos office en un formulario de c# Pin
Bernhard Hiller26-Apr-12 21:52
Bernhard Hiller26-Apr-12 21:52 
QuestionReleaseComObject() or not? Pin
__John_25-Apr-12 23:09
__John_25-Apr-12 23:09 
AnswerRe: ReleaseComObject() or not? Pin
Abhinav S26-Apr-12 6:23
Abhinav S26-Apr-12 6:23 
GeneralRe: ReleaseComObject() or not? Pin
pietvredeveld26-Apr-12 10:30
pietvredeveld26-Apr-12 10:30 
QuestionNeed help in bluetooth OBEX Profile Implementation Pin
sripriya shankar25-Apr-12 19:11
sripriya shankar25-Apr-12 19:11 
Questionknow about basic of all oops concepts Pin
baskaran chellasamy25-Apr-12 18:25
baskaran chellasamy25-Apr-12 18:25 
AnswerRe: know about basic of all oops concepts Pin
Ravi Bhavnani25-Apr-12 18:43
professionalRavi Bhavnani25-Apr-12 18:43 

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.