C # 2nd program, read the data of my website!

Source: Internet
Author: User
Tags constructor
Program | Data because my website is using XML to get D ... Just read the XML (don't beat me ...) Program is the most below, and if you think it is not necessarily the current data on the site, welcome http://www.joysou.com Hey, just want to pull some people.



Here is a quote fragment: Form1.cs

Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.Xml;

Namespace Hellojoysou
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private System.Windows.Forms.DataGrid visitors;
Private System.Windows.Forms.Button GetXML;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;

Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();

//
TODO: Add any constructor code after the InitializeComponent call
//
}

<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}

Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Visitors = new System.Windows.Forms.DataGrid ();
This. GetXML = new System.Windows.Forms.Button ();
((System.ComponentModel.ISupportInitialize) (this. Visitors)). BeginInit ();
This. SuspendLayout ();
//
Visitors
//
This. Visitors.captiontext = "visitors";
This. Visitors.datamember = "";
This. Visitors.headerforecolor = System.Drawing.SystemColors.ControlText;
This. Visitors.location = new System.Drawing.Point (8, 8);
This. Visitors.name = "visitors";
This. Visitors.preferredcolumnwidth = 100;
This. Visitors.size = new System.Drawing.Size (552, 184);
This. Visitors.tabindex = 0;
This. Visitors.navigate + = new System.Windows.Forms.NavigateEventHandler (this. Visitors_navigate);
//
GetXML
//
This. Getxml.location = new System.Drawing.Point (32, 240);
This. Getxml.name = "GetXML";
This. Getxml.size = new System.Drawing.Size (64, 16);
This. Getxml.tabindex = 1;
This. Getxml.text = "GetXML";
This. Getxml.click + = new System.EventHandler (this. Getxml_click);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (568, 278);
This. Controls.Add (this. GetXML);
This. Controls.Add (this. Visitors);
This. MaximizeBox = false;
This. Name = "Form1";
This. Text = "Form1";
This. Load + = new System.EventHandler (this. Form1_Load);
((System.ComponentModel.ISupportInitialize) (this. Visitors)). EndInit ();
This. ResumeLayout (FALSE);

}
#endregion

<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());


}

private void Form1_Load (object sender, System.EventArgs e)
{

}

private void Getxml_click (object sender, System.EventArgs e)
{

XmlDocument xml=new XmlDocument (); Key creates XmlDocument with default constructor
Xml. Load ("http://www.joysou.com/system/nothing.asp"); Load XML file
XmlNode Root=xml. Documentelement.selectnodes ("/joysou"). Item (0);
XmlNodeList Visitor=root. SelectNodes ("Info/visitors/visitor");


DataTable dt = new DataTable ();
Dt. Columns.Add (New DataColumn ("Name", typeof (String));
Dt. Columns.Add (New DataColumn ("Ip", typeof (String));
Dt. Columns.Add (New DataColumn ("Address", typeof (String));
Dt. Columns.Add (New DataColumn ("Os", typeof (String));
Dt. Columns.Add (New DataColumn ("soft", typeof (String));
for (int i=0;i<visitor. count;i++)
{
XmlAttributeCollection Tnode=visitor. Item (i). Attributes;
Dt. Rows.Add (new string[] {tnode["name"]. value,tnode["IP". value,tnode["Address"]. value,tnode["OS"]. value,tnode["soft"]. Value});
}


Visitors.datasource = DT;
}

private void Visitors_navigate (object sender, System.Windows.Forms.NavigateEventArgs ne)
{

}
}
}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.