Visual Studio .NET RSS Headline Viewer





3.00/5 (5 votes)
Mar 23, 2003

53864

393
A macro to show RSS headlines in Visual Studio .NET.
Introduction
There are many programs to display headlines from websites but who needs another app burning up resources! You can read the headlines from Visual Studio .NET 2002 with this handy macro.
This has been converted from the VS6 version from VB script to VB.NET. It illustrates that, code can be converted fairly easily, but CreateObject
is probably a thing of the past!
The improved .NET IDE gives some improvements for free. Firstly, hyperlinks are clickable (they will open a webpage) and secondly they will open within Visual Studio.
Install the macro
Run Visual Studio .NET and go to the Tools menu and select Macro and then Macro IDE. Go to the file menu, select Open and the select File. See MSDN for more info on VS Macros.
Modify the macro
Modify the websites as appropriate in the first sub. Assign the macro to a button and that's it. The original tag removal code was found on CodeProject. The conversion of this code was aided by this article. Have fun.
The code
'------------------------------------------------------------------------
'FILE DESCRIPTION: Web Reader by Davy Mitchell www.latedecember.com
'------------------------------------------------------------------------
Imports EnvDTE
Imports System.Diagnostics
Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions
Public Module Headlines
Sub GetHeadlines()
'DESCRIPTION: Grabs headlines and displays them as text.
Dim RDFText As String
Dim objTextDoc As TextDocument
Dim objEP As EditPoint
'Create a new text document.
Call DTE.ItemOperations.NewFile("General\Text File")
'Get a handle to the new document.
objTextDoc = DTE.ActiveDocument.Object("TextDocument")
objEP = objTextDoc.StartPoint.CreateEditPoint
RDFText = GetHTML("http://christdot.org/backend.php")
objEP.Insert(stripHTML(RDFText))
objEP.Insert("//###################################_
##########################")
RDFText = GetHTML("http://www.latedecember.com/blogger_rss.xml")
objEP.Insert(stripHTML(RDFText))
objEP.Insert("//###################################_
##########################")
'Store
ActiveDocument.Save("C:\news.cpp")
End Sub
Function GetHTML(ByVal strPage As String) As String
Try
Dim oReq As System.Net.HttpWebRequest
Dim oResp As System.Net.HttpWebResponse
oReq = System.Net.HttpWebRequest.Create(strPage)
oResp = oReq.GetResponse
Dim sr As New StreamReader(oResp.GetResponseStream)
Return sr.ReadToEnd()
Catch
'Do something with your error
End Try
End Function
Function stripHTML(ByVal strInput As String)
strInput = Replace(strInput, "<title>", _
vbCr + vbLf + "<title>")
strInput = Replace(strInput, "</title>", vbCr + _
vbLf + "</title>")
strInput = Replace(strInput, "<description>", vbCr + _
vbLf + "<description>")
strInput = Replace(strInput, "</description>", vbCr + _
vbLf + "</description>")
strInput = Replace(strInput, "<link>", "<link>//")
Dim MyregEx As New Regex("<([^>]|\n\r\n)*>", _
RegexOptions.IgnoreCase)
Dim m As Match = MyregEx.Match(strInput)
strInput = MyregEx.Replace(strInput, "")
strInput = Replace(strInput, "\r\n\r\n", "")
strInput = Replace(strInput, "\n\n", "")
stripHTML = strInput
End Function
End Module