You're here: Snippet Directory » Microsoft .NET » ASP.NET (68)
Language:

Kleiner Counter mit C# und XML

Language: Deutsch
Programming Language: C#
Published by: Thomas
Last Update: 4/24/2006
Views: 1106

Description

Ein kleines Beispiel für einen Counter mit C# und XML.

Code

1 #region IncrementAndWriteCount 2 /// <summary> 3 /// Liest den aktuellen Stand des Counters ein, inkrementiert ihn, 4 /// gibt ihn aus und schreibt den neuen Stand zurück ins XML 5 /// </summary> 6 private void IncrementAndWriteCount() { 7 8 // XML laden 9 string xml = Server.MapPath("counter.xml"); 10 XmlDocument counter = new XmlDocument(); 11 counter.Load(xml); 12 13 if(counter.HasChildNodes) { 14 15 // Aktuellen Stand holen 16 XmlNode count = counter.SelectSingleNode("count"); 17 18 int currentCount = int.Parse(count.InnerText); 19 20 // Hochzählen 21 currentCount++; 22 23 // Stand ausgeben und ins XML zurückschreiben 24 litCount.Text = count.InnerText = currentCount.ToString(); 25 counter.Save(xml); 26 } 27 28 } 29 #endregion

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS