Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.IO;
- using System.Windows.Forms;
- namespace WindowsFormsApplication27
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- zapis();
- cteni();
- }
- private void zapis()
- {
- XmlDocument doc = new XmlDocument();
- if (File.Exists("soubor.xml") == false)
- {
- FileStream fst = File.Create("soubor.xml");
- string sablona = "<?xml version=\"1.0\" encoding=\"windows-1250\"?><datumy></datumy>";
- fst.Close();
- File.WriteAllText("soubor.xml", sablona);
- }
- doc.Load("soubor.xml");
- XmlElement element = doc.CreateElement("spusteni");
- XmlAttribute atribut = doc.CreateAttribute("datum");
- atribut.Value = DateTime.Now.ToString();
- element.SetAttributeNode(atribut);
- doc.DocumentElement.InsertBefore(element, doc.DocumentElement.LastChild);
- doc.Save("soubor.xml");
- }
- private void cteni()
- {
- XmlDocument doc = new XmlDocument();
- doc.Load("soubor.xml");
- XmlNode root = doc.DocumentElement;
- foreach (XmlNode node in root.ChildNodes)
- {
- label1.Text += Environment.NewLine + node.Attributes[0].Value;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment