A simple RSS reader written in vb.net

Source: Internet
Author: User
Tags exit chr count integer thread trim
RSS source code is as follows:

Imports System.Xml
Imports System.Threading

Public Class Form1
Inherits System.Windows.Forms.Form
#Region "code generated by the Windows forms Designer"

Public Sub New ()
MyBase.New ()

' This call is required by the Windows Forms Designer.
InitializeComponent ()

' Add any initialization after the InitializeComponent () call

End Sub

' Form overrides dispose to clean up the list of components.
Protected Overloads Overrides Sub Dispose (ByVal disposing as Boolean)
If disposing Then
If not (components are nothing) Then
Components. Dispose ()
End If
End If
Mybase.dispose (disposing)
End Sub

' Required by the Windows Forms Designer
Private Components as System.ComponentModel.IContainer

' NOTE: The following procedure is required by the Windows Forms Designer
' You can use the Windows Forms Designer to modify this procedure.
' Do not modify it using the Code Editor.
Friend WithEvents ListBox1 as System.Windows.Forms.ListBox
Friend WithEvents Button1 as System.Windows.Forms.Button
Friend WithEvents AxWebBrowser1 as Axshdocvw.axwebbrowser
Friend WithEvents Label1 as System.Windows.Forms.Label
Friend WithEvents Label2 as System.Windows.Forms.Label
Friend WithEvents TextBox1 as System.Windows.Forms.TextBox
Friend WithEvents StatusBar1 as System.Windows.Forms.StatusBar
Friend WithEvents Label4 as System.Windows.Forms.Label
<system.diagnostics.debuggerstepthrough () > Private Sub InitializeComponent ()
Dim resources as System.Resources.ResourceManager = New System.Resources.ResourceManager (GetType (FORM1))
Me.listbox1 = New System.Windows.Forms.ListBox
Me.button1 = New System.Windows.Forms.Button
Me.axwebbrowser1 = New Axshdocvw.axwebbrowser
Me.label1 = New System.Windows.Forms.Label
Me.label2 = New System.Windows.Forms.Label
Me.textBox1 = New System.Windows.Forms.TextBox
ME.STATUSBAR1 = New System.Windows.Forms.StatusBar
Me.label4 = New System.Windows.Forms.Label
CType (Me.axwebbrowser1, System.ComponentModel.ISupportInitialize). BeginInit ()
Me.suspendlayout ()
'
' ListBox1
'
Me.ListBox1.Location = New System.Drawing.Point (0, 67)
Me.ListBox1.Name = "ListBox1"
Me.ListBox1.Size = New System.Drawing.Size (727, 108)
Me.ListBox1.TabIndex = 0
'
' Button1
'
Me.Button1.Location = New System.Drawing.Point (633, 5)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size (94, 56)
Me.Button1.TabIndex = 1
Me.Button1.Text = "read"
'
' AxWebBrowser1
'
Me.AxWebBrowser1.Enabled = True
Me.AxWebBrowser1.Location = New System.Drawing.Point (0, 193)
Me.AxWebBrowser1.OcxState = CType (resources. GetObject ("Axwebbrowser1.ocxstate"), System.Windows.Forms.AxHost.State)
Me.AxWebBrowser1.Size = New System.Drawing.Size (727, 476)
Me.AxWebBrowser1.TabIndex = 2
'
' Label1
'
Me.Label1.Location = New System.Drawing.Point (8, 26)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size (616, 15)
Me.Label1.TabIndex = 3
Me.Label1.Text = "Website address:"
'
' Label2
'
Me.Label2.Location = New System.Drawing.Point (8, 45)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size (616, 14)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Site Description:"
'
' TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point (88, 0)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size (536, 20)
Me.TextBox1.TabIndex = 6
Me.TextBox1.Text = "Http://Blog.CSDN.Net/AppleBBS/Rss.aspx"
'
' StatusBar1
'
Me.StatusBar1.Location = New System.Drawing.Point (0, 495)
Me.StatusBar1.Name = "StatusBar1"
Me.StatusBar1.Size = New System.Drawing.Size (726, 22)
Me.StatusBar1.TabIndex = 7
Me.StatusBar1.Text = "StatusBar1"
'
' Label4
'
Me.Label4.Location = New System.Drawing.Point (9, 6)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size (70, 12)
Me.Label4.TabIndex = 8
Me.Label4.Text = "RSS Address:"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
'
' Form1
'
Me.autoscalebasesize = New System.Drawing.Size (5, 13)
Me.clientsize = New System.Drawing.Size (726, 517)
ME.CONTROLS.ADD (ME.LABEL4)
ME.CONTROLS.ADD (ME.STATUSBAR1)
ME.CONTROLS.ADD (Me.textBox1)
ME.CONTROLS.ADD (ME.LABEL2)
ME.CONTROLS.ADD (ME.LABEL1)
ME.CONTROLS.ADD (Me.axwebbrowser1)
ME.CONTROLS.ADD (Me.button1)
ME.CONTROLS.ADD (Me.listbox1)
Me.Name = "Form1"
Me.startposition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Easy RSS Reader"
CType (Me.axwebbrowser1, System.ComponentModel.ISupportInitialize). EndInit ()
Me.resumelayout (False)

End Sub

#End Region
Private thread as thread ' defines a thread
Private Sub Loadrss () ' Read the RSS file and take out the content title process
Statusbar1.text = "reading" & TextBox1.Text & "and efficacy"
Me.loadxmltocache (TextBox1.Text)
Statusbar1.text = "Reading related Web site information"
Me.loadtitle ()
Statusbar1.text = "Reading an RSS content item"
Me.loaditem ()
Statusbar1.text = "complete"
End Sub

Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Try
thread = New thread (AddressOf loadrss)
Thread. Start ()
Catch ex as Exception
MsgBox (ex. ToString)
End Try
End Sub

Private Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
Axwebbrowser1.width = Me.Width
Statusbar1.text = "Ready"
End Sub
Private Sub Loadxmltocache (ByVal URL as String)
' Read the RSS file and store it locally for operation
Dim XmlDocument as New XmlDocument
XmlDocument. Load (URL)
XmlDocument. Save (Application.startuppath & "~doc.xml")

End Sub
Private Sub Loadtitle ()
' Operate from a local file to read information about a Web site in RSS
Dim XmlDocument as New XmlDocument
XmlDocument.Load (Application.startuppath & "~doc.xml")
Dim Mynodelist as XmlNodeList
Mynodelist = Xmldocument.selectnodes ("/rss/channel")
Label1.Text = "website:" & Trim (mynodelist (0). Item ("title"). InnerText ())
Label2.Text = "Description:" & Trim (mynodelist (0). Item ("description"). InnerText ())
End Sub
Private Sub Loaditem ()
' Manipulate from local files to read the title and author of content in RSS
Dim XmlDocument as New XmlDocument
XmlDocument.Load (Application.startuppath & "~doc.xml")
Dim Mynodelist as XmlNodeList
Mynodelist = Xmldocument.selectnodes ("/rss/channel/item")
ListBox1.Items.Clear ()
Dim I as Integer
For i = 0 to mynodelist. Count-1
LISTBOX1.ITEMS.ADD ("[" & Trim (Mynodelist (i)). Item ("Dc:creator"). InnerText ()) & "]" & Trim (Mynodelist (i)). Item ("title"). InnerText ()))
Next
End Sub

Private Sub listbox1_selectedindexchanged (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles listbox1.se Lectedindexchanged
thread = New thread (AddressOf loadhtml)
Thread. Start ()
End Sub
Private Sub loadhtml ()
' Read the contents of the corresponding file in the RSS and display it after the temporary file
Dim XmlDocument as New XmlDocument
XmlDocument.Load (Application.startuppath & "~doc.xml")
Dim Mynodelist as XmlNodeList
Mynodelist = Xmldocument.selectnodes ("/rss/channel/item")
Dim I as Integer
Dim J as Boolean
Dim content as String
Statusbar1.text = "Reading article content"
For i = 0 to mynodelist. Count-1
If Listbox1.selecteditem = "[" & Trim (Mynodelist (i)). Item ("Dc:creator"). InnerText ()) & "]" & Trim (Mynodelist (i)). Item ("title"). InnerText ()) Then
Content = content & "Content = content & "<table width= ' 100% ' height= ' bgcolor= ' #eeeeee ' ><tr><td><b> title:< /b><a href= ' "
Content = content & Trim (mynodelist (i)). Item ("link"). InnerText ())
Content = content & "' target= ' _blank ' >"
Content = content & Trim (mynodelist (i)). Item ("title"). InnerText ())
Content = content & "</a><br><b> author:</b>"
Content = content & Trim (mynodelist (i)). Item ("Dc:creator"). InnerText ())
Content = content & "</tb></tr></table>"
Content = content & formathtml (Mynodelist (i). Item ("description"). InnerText ())
Content = content & "</body>j = Savetextfile (Application.startuppath & "~temp.html", content)
Axwebbrowser1.navigate (Application.startuppath & "~temp.html")
Exit for
End If
Next
Statusbar1.text = "complete"
End Sub
' The process of writing a file
Function Savetextfile (ByVal FilePath As String, ByVal filecontent as String) as Boolean
Dim SW as System.IO.StreamWriter
Try
SW = New System.IO.StreamWriter (FilePath, False)
Sw. Write (filecontent)
Return True
Catch e as Exception
Return False
Finally
If not SW are nothing Then SW. Close ()
End Try
End Function
' The function of taking the URL from the address
Private Function FormatUrl (ByVal str As String) as String
Dim SStr as String
Dim I as Integer
Dim J as Integer
For i = 1 to Len (str)
SSTR = sStr & Mid (str, I, 1)
If Mid (str, I, 1) = "/" Then
J + 1
End If
If j = 3 Then Exit for
Next
Return SSTR
End Function
' The function of changing the address of the relative picture in the content to the absolute address
Private Function formathtml (ByVal str As String) as String
return Replace (str, "src=" & Chr) & "/", "src =" & Chr (+) & FormatUrl (TextBox1.Text))
End Function
End Class



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.