Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            pictureBox1.Image = new System.Drawing.Bitmap(@"E:\reproductor\reproductor\bin\Debug\imagenes\biblioteca.jpg");
            //reproductor\reproductor\bin\Debug\imagenes
            button1.Visible = false;
            //mostrar lista
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(@"E:\reproductor\reproductor\bin\Debug\musicas.txt");
            XmlNodeList canciones = xDoc.GetElementsByTagName("canciones");
            XmlNodeList lista     = ((XmlElement)canciones[0]).GetElementsByTagName("cancion");

            foreach (XmlElement nodo in lista)
            {
                int i = 0;

                album musicatemp = new album();

                XmlNodeList Nombre    = nodo.GetElementsByTagName("nombre");
                XmlNodeList Ubicacion = nodo.GetElementsByTagName("ubicacion");

                musicatemp.Nombre    = Nombre[i].InnerText;
                musicatemp.Ubicacion = Ubicacion[i].InnerText;

                cancioness.Add(musicatemp);
                contador = contador + 1;
            }
            dataGridView1.DataSource = null;
            dataGridView1.Refresh();
            dataGridView1.DataSource = cancioness;
            dataGridView1.Columns[0].DisplayIndex = 1;
            dataGridView1.Update();
        }
Ejemplo n.º 2
0
        private void agregarCancionABibliotecaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog mi_pc = new OpenFileDialog();

            mi_pc.InitialDirectory = @"E:\reproductor\music\";
            if (mi_pc.ShowDialog() == DialogResult.OK)
            {
                string nombre = mi_pc.FileName;
                label2.Text = mi_pc.FileName;
                label1.Text = Path.GetFileNameWithoutExtension(label2.Text);
            }
            //agrega cancion
            string pathxml = @"E:\reproductor\reproductor\bin\Debug\musicas.txt";

            XmlDocument doc = new XmlDocument();

            doc.Load(pathxml);
            XmlNode nodecanciones = doc.CreateElement("cancion");
            XmlNode nodenombre    = doc.CreateElement("nombre");

            nodenombre.InnerText = label1.Text;
            XmlNode nodeubicacion = doc.CreateElement("ubicacion");

            nodeubicacion.InnerText = label2.Text;
            nodecanciones.AppendChild(nodenombre);
            nodecanciones.AppendChild(nodeubicacion);
            doc.SelectSingleNode("canciones").AppendChild(nodecanciones);
            doc.Save(pathxml);
            dataGridView1.Update();
            //limpiar lista
            cancioness.Clear();
            //mostrar lista
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load(@"E:\reproductor\reproductor\bin\Debug\musicas.txt");
            XmlNodeList canciones = xDoc.GetElementsByTagName("canciones");
            XmlNodeList lista     = ((XmlElement)canciones[0]).GetElementsByTagName("cancion");

            foreach (XmlElement nodo in lista)
            {
                int i = 0;

                album       musicatemp = new album();
                XmlNodeList Nombre     = nodo.GetElementsByTagName("nombre");
                XmlNodeList Ubicacion  = nodo.GetElementsByTagName("ubicacion");
                musicatemp.Nombre    = Nombre[i].InnerText;
                musicatemp.Ubicacion = Ubicacion[i].InnerText;
                cancioness.Add(musicatemp);
                // contador = contador + 1;
            }
            dataGridView1.DataSource = null;
            dataGridView1.Refresh();

            dataGridView1.DataSource = cancioness;

            dataGridView1.Columns[0].DisplayIndex = 1;
            dataGridView1.Update();
        }