Hello, I tried to simplify if possible:
.cs
<pre lang="c#">using System;
using System.IO;
using System.Windows;
using Microsoft.Win32;
using System.Xml.Serialization;
namespace ofd1
{
public partial class OpenFileDialogSample : Window
{
public OpenFileDialogSample()
{
InitializeComponent();
}
private void btnOpenFile_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == true)
txtEditor.Text = File.ReadAllText(openFileDialog.FileName);
var path = openFileDialog.FileName;
XmlSerializer serializer= new XmlSerializer (typeof(Book));
StreamReader reader = new StreamReader(path);
var input = Convert.ToString(serializer.Deserialize(reader));
txtEditor2.Text = input;
}
}
}
.xaml
<window x:class="ofd1.OpenFileDialogSample" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="OpenFileDialogSample" Height="300" Width="300">
<dockpanel margin="10">
<wrappanel horizontalalignment="Center" dockpanel.dock="Top" margin="0,0,0,10">
<button name="btnOpenFile" click="btnOpenFile_Click">Open file</button>
</wrappanel>
<textbox name="txtEditor" width="129" />
<textbox name="txtEditor2" />
</dockpanel>
</window>
Now, to get the deserialization in the second textBox, I just need to find the object Book from another project. I did: Solution Explorer- add reference, I found the project map and which one do I have to choose, at this point each I chose is wrong and gives mistake again!!!
Many thanks, please, I am the sheer beginner!!! Try to google but get al I know or does not help with that particular problem!!!