I have the following code:
public class DeserializeAndCompare
{
public static List<string> IntoXML()
{
List<string> PopList = new List<string>();
XmlSerializer serializer = new XmlSerializer(PopList.GetType());
string k = FileToolBox.position0;
FileStream filestreamer = new FileStream(k.ToString(), FileMode.Open);
PopList = (List<string>)serializer.Deserialize(filestreamer);
filestreamer.Close();
return PopList;
}
}
I keep hitting an error with the line: PopList = (List)serializer.Deserialize(filestreamer);
The error: InvalidOperationException was unhandled, There is an error in XML document(1,1).
In this line: FileStream filestreamer = new FileStream(k, FileMode.open);
I am trying to reference the 0th position of an array that holds strings. I'm basically going thru my directory, finding any files with a .xml extension and holding the filename paths in an array.
Here is the code for my array:
public static class FileToolBox
{
public static string position0;
public static void FileSearch()
{
//string position0;
//array holding XML file names
string[] array1 = Directory.GetFiles(@"s:\project", "*.xml");
Array.Sort(array1);
Array.Reverse(array1);
Console.WriteLine("Files:");
foreach (string fileName in array1)
{
Console.WriteLine(fileName);
}
position0 = array1[0];
}
public static string Position0
{
get
{
return position0;
}
set
{
position0 = value;
}
}
}
Am i missing something here? How do i get rid of this error?
Thanks in advance for the help.