Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void updateData(string url, string file)
- {
- if (url == "")
- {
- MessageBox.Show("No address specified !");
- }
- else
- {
- string http = url.Substring(0, 6);
- if (http != "http://")
- {
- http = "http://";
- url = http + url;
- }
- if (!check_link(url, file))
- {
- MessageBox.Show("This link " + url + " already exists !");
- }
- else
- {
- XmlDocument document = new XmlDocument();
- document.Load(file);
- XmlElement element = document.CreateElement("link");
- element.InnerText = url;
- document.DocumentElement.AppendChild(element);
- document.PreserveWhitespace = false;
- XmlTextWriter xtw = new XmlTextWriter(file, Encoding.UTF8);
- document.WriteTo(xtw);
- xtw.Close();
- document.Save(file);
- showData(file);
- }
- }
- }
- public bool check_link(string url,string file)
- {
- bool status = false;
- XmlReaderSettings setari = new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true };
- XmlReader reader = XmlReader.Create(file,setari);
- while(reader.Read())
- {
- switch (reader.NodeType)
- {
- case XmlNodeType.Element :
- switch (reader.Name)
- {
- case "link": {
- string own_value = reader.ReadString();
- if (own_value == url)
- {
- status=false;
- }
- else
- {
- status=true;
- }
- break; }
- }
- break;
- }
- }
- reader.Close();
- return status;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement