chetan_rajakumar
New member
- Joined
- Oct 28, 2014
- Messages
- 1
- Programming Experience
- 3-5
Hi,
I am having a requirement which states to Read the contents of '.ser' files present in a folder and save each filenames and file contents of files in that folder to an xml file.
I tried with the below code but getting Runtime.Serialization Exception --> {"The input stream is not a valid binary format. The starting contents (in bytes) are: AC-ED-00-05-73-72-00-10-6A-61-76-61-2E-75-74-69-6C ..."}. Please someone help me out to complete the stated requirement.
Getting exception @ this line string content = (string)bf.Deserialize(fileStream);
XmlWriterxmlWriter = XmlWriter.Create("C:\\TestFile.ser");
// Opens the document
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("SerializedFiles");
foreach (string file in Directory.EnumerateFiles(serializedFilesFolder, "*.SER"))
{
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
string content = (string)bf.Deserialize(fileStream);
//BinaryFormatter bf = new BinaryFormatter();
//ArrayList a = (ArrayList)bf.Deserialize(fileStream);
fileStream.Close();
xmlWriter.WriteStartElement("SerializedFile");
xmlWriter.WriteElementString("FileName", Path.GetFileName(file));
xmlWriter.WriteElementString("Content", content);
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
I did some search for "Reading the '.ser' file in C#", but i found only the java related examples. Please let me know the correct way or some sample code to achieve the requirement.
Thanks in advance.
Regards,
Chetan.
I am having a requirement which states to Read the contents of '.ser' files present in a folder and save each filenames and file contents of files in that folder to an xml file.
I tried with the below code but getting Runtime.Serialization Exception --> {"The input stream is not a valid binary format. The starting contents (in bytes) are: AC-ED-00-05-73-72-00-10-6A-61-76-61-2E-75-74-69-6C ..."}. Please someone help me out to complete the stated requirement.
Getting exception @ this line string content = (string)bf.Deserialize(fileStream);
XmlWriterxmlWriter = XmlWriter.Create("C:\\TestFile.ser");
// Opens the document
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("SerializedFiles");
foreach (string file in Directory.EnumerateFiles(serializedFilesFolder, "*.SER"))
{
FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
string content = (string)bf.Deserialize(fileStream);
//BinaryFormatter bf = new BinaryFormatter();
//ArrayList a = (ArrayList)bf.Deserialize(fileStream);
fileStream.Close();
xmlWriter.WriteStartElement("SerializedFile");
xmlWriter.WriteElementString("FileName", Path.GetFileName(file));
xmlWriter.WriteElementString("Content", content);
xmlWriter.WriteEndElement();
}
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
I did some search for "Reading the '.ser' file in C#", but i found only the java related examples. Please let me know the correct way or some sample code to achieve the requirement.
Thanks in advance.
Regards,
Chetan.