Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:05:45+00:00 2026-05-29T22:05:45+00:00

I Save An onject into a xml file with serialize like this: FileStream stream

  • 0

I Save An onject into a xml file with serialize like this:

        FileStream stream = new FileStream(tempFilename,FileMode.Create);
        XmlSerializer serializer = new XmlSerializer(newType);
        serializer.Serialize(stream,objectname);

but with this code i can just enter one item in my xml file and it will be overwrite if i insert new item in it.how can i enter multiple item in my file?Sholud I Use List For it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:05:46+00:00Added an answer on May 29, 2026 at 10:05 pm

    I do this quite often. I usually use a top level class that encapsulates the collection property as a member and has a one to one relationship with the xml file. Members of that class can be collections or simple attributes etc.

    Here is a code snippet for having a collection of custom objects:

    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlRootAttribute(ElementName = "DeployRuns", Namespace = "", IsNullable = false)]
    public class DeployRuns : List<RunDetail>
    {
    

    And then if you want to encapsulate your collection inside another class which will be serialized, see the bottom property of this class:

    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
    public class DeployDetails
    {
       public DeployDetails()
       {
          this.DeployRuns = new DeployRuns();
       }
    
       [System.Xml.Serialization.XmlAttributeAttribute("sourcePath")]
       public string SourcePath { get; set; }
    
       [System.Xml.Serialization.XmlAttributeAttribute("archiveDestinationPath")]
       public string ArchiveDestinationPath { get; set; }
    
       [System.Xml.Serialization.XmlAttributeAttribute("databaseDestinationPath")]
       public string DatabaseDestinationPath { get; set; }
    
       public DeployRuns DeployRuns { get; set; }
    }
    

    And to finish off the code example, here is my top level class for this hierarchy:

    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlRootAttribute(ElementName = "ExecutionHistory", Namespace = "", IsNullable = false)]
    public class ExecutionHistory
    {
       public ExecutionHistory()
       {
          this.CaptureDetails = new CaptureDetails();
          this.DeployDetails = new DeployDetails();
       }
    
       [XmlElementAttribute("CaptureDetails", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
       public CaptureDetails CaptureDetails { get; set; }
    
       [XmlElementAttribute("DeployDetails", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
       public DeployDetails DeployDetails { get; set; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to parse an XML file and save this information into object.
I were using FileStream to Serialize an Object to Xml and Save to the
How to save c++ object into a xml file and restore back?
I am using cURL to get an XML feed and save it into an
i need to save a xml file from a server.. i found a code
I am trying to serialize an object & save it into a Sql server
I want to save records fetched from database in an XML file, take x
I'm doing an iPhone app that reads data from XML file, turn them into
I'm trying to save a local copy of an xml file, and then open
I have the following method to save an Object to a file: // Save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.