Hello, I have an error in my code, i want to deserialize different XML Files and open it in textboxes, the problem i had is when it takes the file path, i Think that there is where the error is, because it takes a one exact file path(ex.):
FileStream FS = new FileStream("example.analy", FileMode.Open, FileAccess.Read);
But i replaced it with this
FileStream FS = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
To read the files that were selected in the openfiledialog.
This is my complete code:
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openFileDialog1.FileName))
{
if ((openFileDialog1.OpenFile()) != null)
{
if (openFileDialog1.FileName != null)
{
openFileDialog1.Filter = "Analytica Files | *.analy";
XmlSerializer XS = new XmlSerializer(typeof(Reminders.Information));
FileStream FS = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
Information Info = (Information)XS.Deserialize(FS);
XS.Deserialize(FS);
Settings.Default.Counter++;
Settings.Default.Save();
The problem is that when I try to open a file, appears the next error:
System.InvalidOperationException: 'Error en el documento XML (0, 0).'
Inner Exception
XmlException: Missing Root Element.
What I have tried:
This is my complete code:
<pre> if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (File.Exists(openFileDialog1.FileName))
{
if ((openFileDialog1.OpenFile()) != null)
{
if (openFileDialog1.FileName != null)
{
openFileDialog1.Filter = "Analytica Files | *.analy";
XmlSerializer XS = new XmlSerializer(typeof(Reminders.Information));
FileStream FS = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
Information Info = (Information)XS.Deserialize(FS);
XS.Deserialize(FS);
Settings.Default.Counter++;
Settings.Default.Save();