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

  • Home
  • SEARCH
  • 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 8241533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:51:48+00:00 2026-06-07T20:51:48+00:00

I have a program written in C# that serializes data into binary and write

  • 0

I have a program written in C# that serializes data into binary and write it on the disk. If I want to add more data to this file, fist I have to deserialise whole file and then append more serialized data to it. Is it possible to append data to this serialized file without deserialising the existing data so that I can save some time during whole process?

  • 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-06-07T20:51:49+00:00Added an answer on June 7, 2026 at 8:51 pm

    Now that we know (comments) that we’re talking about a DataTable/DataSet via BinaryFormatter, it becomes clearer. If your intention is for that to appear as extra rows in the existing table, then no: that isn’t going to work. What you could do is append, but deserialize each table in turn, then manually merge the contents. That is probably your best bet with what you describe. Here’s an example just using 2, but obviously you’d repeat the deserialize/merge until EOF:

    var dt = new DataTable();
    dt.Columns.Add("foo", typeof (int));
    dt.Columns.Add("bar", typeof(string));
    
    dt.RemotingFormat = SerializationFormat.Binary;
    var ser = new BinaryFormatter();
    using(var ms = new MemoryStream())
    {
        dt.Rows.Add(123, "abc");
        ser.Serialize(ms, dt); // batch 1
        dt.Rows.Clear();
        dt.Rows.Add(456, "def");
        ser.Serialize(ms, dt); // batch 2
    
        ms.Position = 0;
    
        var table1 = (DataTable) ser.Deserialize(ms);
    
        // the following is the merge loop that you'd repeat until EOF
        var table2 = (DataTable) ser.Deserialize(ms);
        foreach(DataRow row in table2.Rows) {
            table1.ImportRow(row);
        }
    
        // show the results
        foreach(DataRow row in table1.Rows)
        {
            Console.WriteLine("{0}, {1}", row[0], row[1]);
        }
    }
    

    However! Personally I have misgivings about both DataTable and BinaryFormatter. If you know what your data is, there are other techniques. For example, this could be done very simply with “protobuf”, since protobuf is inherently appendable. In fact, you need to do extra to not append (although that is simple enough too):

    [ProtoContract]
    class Foo
    {
        [ProtoMember(1)]
        public int X { get; set; }
        [ProtoMember(2)]
        public string Y { get; set; }
    
    }
    [ProtoContract]
    class MyData
    {
        private readonly List<Foo> items = new List<Foo>();
        [ProtoMember(1)]
        public List<Foo> Items { get { return items; } }
    }
    

    then:

    var batch1 = new MyData { Items = { new Foo { X = 123, Y = "abc" } } };
    var batch2 = new MyData { Items = { new Foo { X = 456, Y = "def" } } };
    using(var ms = new MemoryStream())
    {
        Serializer.Serialize(ms, batch1);
        Serializer.Serialize(ms, batch2);
        ms.Position = 0;
        var merged = Serializer.Deserialize<MyData>(ms);
        foreach(var row in merged.Items) {
            Console.WriteLine("{0}, {1}", row.X, row.Y);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program written in C++, that opens a binary file(test.bin), reads it
I have a program (written in C#) that reads/writes its data directly (direct file
I Have a program written in VB6 that reads a long text file and
I have written a program that uses qhttp to get a webpage. This works
I have a program written in VB.NET which stops a service that uses file
I have a program written in python that uploads an archive (zip file) to
I have a program written in Delphi XE that plays a WAV file using
I have this program written in C++ Builder 6. I didn't write all the
I have a program written in Java that reads an excel file and output
I have a program written in Java that reads in a file that is

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.