Hi mọi người, mấy hôm nay HungCoder.Com bận đi làm quá nên không viết bài chia sẽ cho mọi người thủ thuật lấy bài viết mới nhất bằng RSS mà các bạn đã cài đặt cho blog của các bạn :D


Hiện tại chương trình cập nhật này mình chưa có thời gian để phát triển thêm một số tiện ích khác cho mọi người được vì thời gian của mình ít quá nên không có nhiều thời gian chỉnh sữa cho nó oke chút :D

Nhưng hiện tại HungCoder.Com viết bài chia sẽ này cho mọi người biết cách thức hoạt động và lấy ra link như thế nào của chương trình. Vì chương trình này lúc xưa mình cũng đã làm một ứng dụng view link từ RSS, nhưng do đổi blog nên bài viết đó đã bị xóa mất tiêu nên chưa phát triển lại ứng dụng đó được. :D

Full Đoạn Code
Đầu tiên bạn Import những dữ kiện này vào chương trình.
Option Strict On
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.Globalization
Imports System.Net
Imports System.Xml
Imports System.IO

Tiếp theo các bạn thêm vào Form một thẻ "DataGridView1". Và các bạn bỏ toàn bộ code bên dưới vào Form1_Load để khi khởi động là ứng dụng tự động lấy dữ liệu bài viết luôn. Bên dưới là toàn bộ đoạn code.
Option Strict On
Option Explicit On

Imports Microsoft.VisualBasic
Imports System
Imports System.Globalization
Imports System.Net
Imports System.Xml
Imports System.IO
Public Class Form1
Dim myRequest As WebRequest
Dim myResponse As WebResponse
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'link cần thay đổi để lấy dữ liệu của trang blog bạn cần.
Dim url As String = "http://www.hungcoder.com/feeds/posts/default"
Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim response = rssFeed.GetResponse()
Dim rssStream = response.GetResponseStream()

Dim rssDoc As New XmlDocument()
rssDoc.Load(rssStream)
Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
Dim i As Integer = 0
Dim dt As DataTable = New DataTable("table")
dt.Columns.Add("title", Type.GetType("System.String"))
dt.Columns.Add("link", Type.GetType("System.String"))

While i < rssItems.Count
Dim node As XmlNode = rssItems.Item(i).SelectSingleNode("title")
Dim title As String
Dim link As String
If node IsNot Nothing Then
title = node.InnerText
Else
title = ""
End If

node = rssItems.Item(i).SelectSingleNode("link")
If node IsNot Nothing Then
link = node.InnerText
Else
link = ""
End If
Dim dr As DataRow = dt.NewRow()
dr("title") = title
dr("link") = link

dt.Rows.Add(dr)

i += 1
End While

DataGridView1.DataSource = dt
DataGridView1.Columns(1).Width = 900
DataGridView1.Columns(0).Width = 420
End Sub

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
Try
If Me.WindowState = FormWindowState.Minimized Then
Me.Visible = False
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(1, "Thông Báo", "HungCoder.Com Đang Ẩn Nấp Tại Đây.", ToolTipIcon.Info)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
Me.Show()
NotifyIcon1.ShowBalloonTip(500, "Thông Báo", "HungCoder.Com Đã Có Mặt.", ToolTipIcon.Info)
End Sub
Private Sub NotifyIcon1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Try
Me.Visible = True
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub AuthorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AuthorToolStripMenuItem.Click
Process.Start("https://www.hungcoder.com/p/about.html")
End Sub

Private Sub MyBlogToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBlogToolStripMenuItem.Click
Process.Start("https://link.hungcoder.com/")
End Sub

Private Sub FacebookToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FacebookToolStripMenuItem.Click
Process.Start("https://link.hungcoder.com/go/facebook")
End Sub
End Class

Các bạn có thể thay đổi đoạn link RSS mình bôi đỏ trên blog bằng một Textbox để người dùng nào tải về cũng có thể lấy được link bài viết các trang khác :D

VIDEO DEMO.


DOWNLOAD DEMO
Hiện Tại HungCoder.Com Đang Bị Lỗi DNS Nên Không Thể Download File Từ Sever. Mong Các Bạn Thông Cảm
Chúc các bạn thành công.