Click here to Skip to main content
15,927,344 members
Home / Discussions / C#
   

C#

 
GeneralRe: .NET Benchmark Challenge Pin
Andres Manggini20-Mar-02 15:43
Andres Manggini20-Mar-02 15:43 
GeneralRe: .NET Benchmark Challenge Pin
Chris Maunder21-Mar-02 0:11
cofounderChris Maunder21-Mar-02 0:11 
Generalcreating a control as a container (like SSTabs) Pin
20-Mar-02 5:32
suss20-Mar-02 5:32 
GeneralUsing Collections of objects as public properties Pin
20-Mar-02 5:30
suss20-Mar-02 5:30 
QuestionGetTextExtent in C#? Pin
19-Mar-02 23:55
suss19-Mar-02 23:55 
AnswerRe: GetTextExtent in C#? Pin
Alexander Kojevnikov20-Mar-02 0:15
Alexander Kojevnikov20-Mar-02 0:15 
GeneralFighting with ADO.NET Pin
Mazdak19-Mar-02 23:20
Mazdak19-Mar-02 23:20 
GeneralSerialization (save and loading) Pin
BLaZiNiX19-Mar-02 14:00
BLaZiNiX19-Mar-02 14:00 
I created an application that Store an ArrayList (of file and file data) in a File using Serialization with BinaryFormater.

What I want to do it's to load each filepath stored in the file I created with the Serialization and create the path. After the path is created I want to store the data of the equivalent file that is store in the file I created with the Serialization in the new file I created in the loading process.

My problem is here :

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;


namespace MultipleFile
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private ArrayList r,w,data,read,n,m;
private BinaryFormatter a,b,c;
private StreamReader reader;
private StreamWriter sr;
private string path,content,npath;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
///
/// Required designer variable.
///

private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
r = new ArrayList();
w = new ArrayList();
data = new ArrayList();
read = new ArrayList();
a = new BinaryFormatter();
b = new BinaryFormatter();
c = new BinaryFormatter();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 20);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "Open";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(32, 52);
this.button2.Name = "button2";
this.button2.TabIndex = 1;
this.button2.Text = "Create";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(32, 88);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "Write";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(32, 120);
this.button4.Name = "button4";
this.button4.TabIndex = 3;
this.button4.Text = "Test";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(128, 158);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button4,
this.button3,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog o = new OpenFileDialog();
o.Filter = "All Files (*.*)|*.*";
if(o.ShowDialog() == DialogResult.OK)
{
r.Add(o.FileName);
reader = new StreamReader(o.FileName);
string text = reader.ReadToEnd();
data.Add(text);

}
}

private void button2_Click(object sender, System.EventArgs e)
{
Stream s = File.Open("D:\\path.dat",FileMode.Create,FileAccess.ReadWrite);
a.Serialize(s,r);

Stream ss = File.Open("D:\\data.dat",FileMode.Create,FileAccess.ReadWrite);
b.Serialize(ss,data);


s.Close();
ss.Close();
}

--->> private void button3_Click(object sender, System.EventArgs e)
{
Stream s = File.Open("D:\\path.dat",FileMode.Open,FileAccess.Read,FileShare.None);
w = (ArrayList)a.Deserialize(s);

foreach(string i in w)
{
MessageBox.Show(i);

}
Stream ss = File.Open("D:\\data.dat",FileMode.Open,FileAccess.Read);
w = (ArrayList)a.Deserialize(ss);
foreach(string d in w)
{
MessageBox.Show(d);
}

s.Close();
ss.Close();
}

private void button4_Click(object sender, System.EventArgs e)
{
Stream s = File.Open("D:\\test.dat",FileMode.Open,FileAccess.Read);
w = (ArrayList)b.Deserialize(s);
read = (ArrayList)b.Deserialize(s);


s.Close();
}
}
}

can you copy this code and try it and you will see what I mean. I want to replace the button3_onclick event where the MEssageBox are with a File Creation and data transfer to the new file created... and I want to create it in ONE file (store the data and the file path in the same file not in two separate files)

Thanks a lot, thanks thanks thanks Smile | :)

Jonathan Pouliot
GeneralRe: Serialization (save and loading) Pin
Andres Manggini19-Mar-02 14:34
Andres Manggini19-Mar-02 14:34 
GeneralRe: Serialization (save and loading) Pin
BLaZiNiX19-Mar-02 15:32
BLaZiNiX19-Mar-02 15:32 
GeneralRe: Serialization (save and loading) Pin
Andres Manggini19-Mar-02 16:10
Andres Manggini19-Mar-02 16:10 
GeneralRe: Serialization (save and loading) Pin
BLaZiNiX19-Mar-02 16:38
BLaZiNiX19-Mar-02 16:38 
QuestionC# replacement for GetAsyncKeyState? Pin
Zombies with Coffee, LLC19-Mar-02 10:49
professionalZombies with Coffee, LLC19-Mar-02 10:49 
AnswerRe: C# replacement for GetAsyncKeyState? Pin
Zombies with Coffee, LLC19-Mar-02 10:57
professionalZombies with Coffee, LLC19-Mar-02 10:57 
AnswerRe: C# replacement for GetAsyncKeyState? Pin
ez219-Mar-02 11:27
ez219-Mar-02 11:27 
GeneralUpdating DataSource Pin
Mazdak19-Mar-02 10:31
Mazdak19-Mar-02 10:31 
GeneralRe: Updating DataSource Pin
Andres Manggini19-Mar-02 11:34
Andres Manggini19-Mar-02 11:34 
GeneralRe: Updating DataSource Pin
Mazdak19-Mar-02 11:42
Mazdak19-Mar-02 11:42 
GeneralRe: Updating DataSource Pin
Andres Manggini19-Mar-02 12:37
Andres Manggini19-Mar-02 12:37 
GeneralRe: Updating DataSource Pin
Mazdak19-Mar-02 19:39
Mazdak19-Mar-02 19:39 
GeneralRe: Updating DataSource Pin
Andres Manggini20-Mar-02 1:57
Andres Manggini20-Mar-02 1:57 
GeneralRe: Updating DataSource Pin
Andres Manggini20-Mar-02 2:00
Andres Manggini20-Mar-02 2:00 
GeneralRe: Updating DataSource Pin
Mazdak20-Mar-02 2:41
Mazdak20-Mar-02 2:41 
GeneralOverriding simple methods... Pin
Zombies with Coffee, LLC19-Mar-02 6:02
professionalZombies with Coffee, LLC19-Mar-02 6:02 
GeneralRe: Overriding simple methods... Pin
Christian Graus19-Mar-02 10:42
protectorChristian Graus19-Mar-02 10:42 

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.