I've got this code.
const int maxbooks = 5;
Book[] booklist = new Book[maxbooks];
FileStream fs = File.Open(@"books.txt", FileMode.Open, FileAccess.Read);
SoapFormatter sf = new SoapFormatter();
try
{
// something here, deserializing file and assigning to the array
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
fs.Close();
}
I've figured out (or at least, I THINK I've figured out) how to serialize the original array of objects in a separate program. I'm now looking to de serialize that, and create a new array with the de serialized data. Just for reference, here's the other file where I serialized the original array
Book firstbook = new Book("Jimbob", "Jimbob book", "first edition", "Jimbob publishing", "1991");
Book secondbook = new Book("Greg", "Greg book", "third edition", "Unholy publishing", "2010");
Book thirdbook = new Book("Pingu", "Pingu book", "tenth edition", "Antarctic publishing", "1897");
Book fourthbook = new Book("Patrick", "Patrick book", "seventh edition", "underwater publishing", "1991");
Book fifthbook = new Book("Sally", "Sally book", "first edition", "Wowpublishing", "2015");
const int maxbooks = 5;
Book[] booklist = new Book[maxbooks];
booklist[0] = firstbook;
booklist[1] = secondbook;
booklist[2] = thirdbook;
booklist[3] = fourthbook;
booklist[4] = fifthbook;
// writing to a file
FileStream fs = File.Open(@"books.txt", FileMode.Create, FileAccess.Write);
SoapFormatter sf = new SoapFormatter();
int bookindex = 0;
try
{
while (bookindex < maxbooks)
{
sf.Serialize(fs, booklist[bookindex]);
bookindex += 1;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
fs.Close();
}
Using SOAP serialization for the moment with this. Any help will be appreciated.