somewhere in... blog
x
ফোনেটিক ইউনিজয় বিজয়

Structure Array Read & Write using Serialize/Desrialize in a File using c#.

২২ শে সেপ্টেম্বর, ২০০৯ রাত ১:০২
এই পোস্টটি শেয়ার করতে চাইলে :

Hi Guys!!
This sample code will do help you for the above topic named here, and solved like this already.. any issues you make me a query i give further information..

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Runtime.Serialization;
namespace fileSerialization
{
public partial class Form1 : Form
{
TestStruc mp,np;
BinaryFormatter bformatter;
Stream stream;
public Form1()
{
s1 = new TestStruc();
s1.EmpId = 1;
s1.EmpName = “Raj”;
s1.CompCode = “Code1″;
s2 = new TestStruc();
s2.EmpId = 2;
s2.EmpName = “Peter”;
s2.CompCode = “Code2″;
}
[Serializable()] //Set this attribute to all the classes that want to serialize
public struct TestStruc : ISerializable
{
public int EmpId;
public string EmpName;
public string CompCode;
//Serialization function.
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
//You can use any custom name for your name-value pair. But make sure you
// read the values with the same name. For ex:- If you write EmpId as “EmployeeId”
// then you should read the same with “EmployeeId”
info.AddValue(”EmployeeId”, EmpId);
info.AddValue(”EmployeeName”, EmpName);
info.AddValue(”CompCode”, CompCode);
}
//Deserialization constructor.
public TestStruc(SerializationInfo info, StreamingContext ctxt)
{
//Get the values from info and assign them to the appropriate properties
EmpId = (int)info.GetValue(”EmployeeId”, typeof(int));
EmpName = (String)info.GetValue(”EmployeeName”, typeof(string));
CompCode = (String)info.GetValue(”CompCode”, typeof(string));
}
// Serialise the object Stream.
private void button1_Click(object sender, EventArgs e)
{
stream = File.Open(”EmployeeInfo.txt”, FileMode.Create);
bformatter = new BinaryFormatter();
bformatter.Serialize(stream, s1);
bformatter.Serialize(stream, s2);
stream.Close();
}
private void button2_Click(object sender, EventArgs e)
{
//Open the file written above and read values from it.
stream = File.Open(”EmployeeInfo.txt”, FileMode.Open);
//StreamReader stream1 = new StreamReader(stream);
bformatter = new BinaryFormatter();
Console.WriteLine(”Reading Employee Information”);
while (stream.Position < stream.Length)
{
s1 = (TestStruc)bformatter.Deserialize(stream);
MessageBox.Show(”Employee Id: {0}” + mp.EmpId.ToString());
MessageBox.Show(”Employee Name: {0}” + s1.EmpName);
MessageBox.Show(”CompCode” + s1.CompCode);
}
}
}
}
সর্বশেষ এডিট : ২২ শে সেপ্টেম্বর, ২০০৯ রাত ১:০৩
০টি মন্তব্য ০টি উত্তর

আপনার মন্তব্য লিখুন

ছবি সংযুক্ত করতে এখানে ড্রাগ করে আনুন অথবা কম্পিউটারের নির্ধারিত স্থান থেকে সংযুক্ত করুন (সর্বোচ্চ ইমেজ সাইজঃ ১০ মেগাবাইট)
Shore O Shore A Hrosho I Dirgho I Hrosho U Dirgho U Ri E OI O OU Ka Kha Ga Gha Uma Cha Chha Ja Jha Yon To TTho Do Dho MurdhonNo TTo Tho DDo DDho No Po Fo Bo Vo Mo Ontoshto Zo Ro Lo Talobyo Sho Murdhonyo So Dontyo So Ho Zukto Kho Doye Bindu Ro Dhoye Bindu Ro Ontosthyo Yo Khondo Tto Uniswor Bisworgo Chondro Bindu A Kar E Kar O Kar Hrosho I Kar Dirgho I Kar Hrosho U Kar Dirgho U Kar Ou Kar Oi Kar Joiner Ro Fola Zo Fola Ref Ri Kar Hoshonto Doi Bo Dari SpaceBar
এই পোস্টটি শেয়ার করতে চাইলে :
আলোচিত ব্লগ

'ট্রিট' বা 'উদযাপন' মানে স্রেফ খাওয়া-দাওয়াই মূখ্য কেন??

লিখেছেন শেহজাদ আমান, ৩১ শে মার্চ, ২০২৬ বিকাল ৪:৩৭



আমাদের উদযাপনটা হয়ে গেছে অনেকটা খাওয়া-দাওয়া কেন্দ্রিক? 'ট্রিট' বা 'সেলিব্রেশন' বলতে আমরা কেবল খাওয়া-দাওয়াকেই বুঝি...কিন্তু এটা কিন্তু ভিন্নরকমভাবেও করা যায় নিঃসন্দেহে!

প্রিয় কেউ ভালো কোনোকিছু করলে, সফলতা পেলে বা... ...বাকিটুকু পড়ুন

মাওলার দায়িত্ব পেয়ে সেই দায়িত্ব পালন না করায় হযরত আলীকে (রা.) মাওলা বলা ঠিক না

লিখেছেন মহাজাগতিক চিন্তা, ৩১ শে মার্চ, ২০২৬ সন্ধ্যা ৬:১৮



সূরাঃ ৬ আনআম, ১৫৩ নং আয়াতের অনুবাদ-
১৫৩। আর এপথই আমার সিরাতিম মুসতাকিম (সরল পথ)। সুতরাং তোমরা এর অনুসরন করবে, এবং বিভিন্ন পথ অনুসরন করবে না, করলে তা’ তোমাদেরকে... ...বাকিটুকু পড়ুন

আমাদের নিজেদের না পাওয়া গুলো অন্যদের পেতে সাহায্য করা উচিত।

লিখেছেন নূর আলম হিরণ, ৩১ শে মার্চ, ২০২৬ রাত ৯:৪২


আমরা মানুষেরা সবসময় ভালো থাকতে চাই। ভালো খেতে চাই, ভালো পড়তে চাই, ভালো চাকুরী/ব্যবসা করতে চাই। কিন্তু বেশিরভাগ সময়ই আমাদের চাওয়ার সাথে পাওয়ার মিল থাকেনা। এই চাওয়ার সাথে পাওয়ার মিল... ...বাকিটুকু পড়ুন

ধান ভানতে শীবের গীত : প্রজা বলে শীত ! শীত!!

লিখেছেন স্বপ্নের শঙ্খচিল, ৩১ শে মার্চ, ২০২৬ রাত ১১:২২

ধান ভানতে শীবের গীত : প্রজা বলে শীত ! শীত!!


সমুদ্রে বড় জাহাজ যখন ডুবতে থাকে, তখন কে ধনী বা কে গরীব প্রকৃতি তার বাছ-বিচার করেনা ।
বা বলা চলে, কে পাপী... ...বাকিটুকু পড়ুন

এতো সুর আর এতো গান - আমার কণ্ঠে

লিখেছেন সাড়ে চুয়াত্তর, ০১ লা এপ্রিল, ২০২৬ রাত ২:০০

একটা হারানো দিনের গান গাওয়ার চেষ্টা করেছি (Cover Song)। আশা করি সবাই উপভোগ করবেন।

গান - এতো সুর আর এতো গান
মূল গায়ক - সুবীর সেন
গীতিকার এবং সুরকার - সুধিন... ...বাকিটুকু পড়ুন

×