Exemplo n.º 1
0
        private async void pregledBin()
        {
            openFileDialog1.Filter           = "DAT files (*.dat)|*.dat";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.EndsWith(".dat"))
            {
                ;
            }
            {
                using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open))
                {
                    BinaryReader    xr = new BinaryReader(fs);
                    BinaryFormatter xs = new BinaryFormatter();
                    List <Knjiga>   l  = new List <Knjiga>(await Task.Run(() => xs.Deserialize(fs) as List <Knjiga>));

                    if (l != null)
                    {
                        DataGridKnjige dgu = new DataGridKnjige(l);
                        dgu.ShowDialog();
                    }
                    fs.Close();
                }
            }
        }
Exemplo n.º 2
0
        private async void pregledXml()
        {
            openFileDialog1.Filter           = "XML files (*.xml)|*.xml";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.EndsWith(".xml"))
            {
                ;
            }
            {
                using (FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open))
                {
                    XmlReader     xr = XmlReader.Create(fs);
                    XmlSerializer xs = new XmlSerializer(typeof(List <Knjiga>), new Type[] { typeof(Strip), typeof(NaucniRad) });
                    List <Knjiga> l  = new List <Knjiga>(await Task.Run(() => xs.Deserialize(xr) as List <Knjiga>));

                    if (l != null)
                    {
                        DataGridKnjige dgu = new DataGridKnjige(l);
                        dgu.ShowDialog();
                    }
                    fs.Close();
                }
            }
        }