I click a button in my windows form app, and it opens a file open box. I click the xml file I want to open and I want the data to populate the text fields in my windows form, but I get System.ArgumentException: 'Illegal characters in path.' error on the FileStream line of code.
private void button2_Click(object sender, EventArgs e)
{
// On click Open the file
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFileDialog1.FileName);
XmlSerializer serializer = new XmlSerializer(typeof(ContactLead));
// Save file contents to variable
var fileResult = sr.ReadToEnd();
FileStream myFileStream = new FileStream(fileResult, FileMode.Open, FileAccess.Read, FileShare.Read);
ContactLead contactLead = (ContactLead)serializer.Deserialize(myFileStream);
this.textboxFirstName.Text = contactLead.firstname;
this.textboxLastName.Text = contactLead.lastname;
this.textboxEmail.Text = contactLead.email;
}
}