I am trying to get my winform application to read the xml file stored in dropbox. But when he gets to
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "updater"))
Then it will not continue. but if I delete && (reader.Name == "updater"), then it continues, but it still does not read the value of "version" and "url".
Link to update.xml: https://www.dropbox.com/s/25gcpllsqsj1qrq/update.xml
Below is my C # code in my project. I am trying to read update.xml in Dropbox with an XmlTextReader, but I just never get any values ββback!
I tried posting messages to show me reader.Name, but it returns "html" instead of "updater".
No need to be an XmlTextReader. While the solution works, then its fine: D
Any help would be appreciated.
private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e) { Version newVersion = null; string url = ""; XmlTextReader reader = null; try { string xmlURL = "https://www.dropbox.com/s/25gcpllsqsj1qrq/update.xml"; reader = new XmlTextReader(xmlURL); reader.MoveToContent(); string elementName = ""; if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "updater")) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) elementName = reader.Name; else { if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue)) { switch (elementName) { case "version": newVersion = new Version(reader.Value); break; case "url": url = reader.Value; break; } } } } } } catch (Exception) { } finally { if (reader != null) reader.Close(); } Version curVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; if (curVersion.CompareTo(newVersion) < 0) { string title = "New version detected."; string question = "Download the new version?"; if (DialogResult.Yes == MessageBox.Show(this, question, title, MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { System.Diagnostics.Process.Start(url); } } else { MessageBox.Show("The program is up to date!"); } }
source share