Click here to Skip to main content
15,881,757 members
Articles / Programming Languages / Visual Basic
Article

Visual Studio .NET RSS Headline Viewer

Rate me:
Please Sign up or sign in to vote.
3.00/5 (5 votes)
9 May 2003 53.6K   22   1
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

VB
'------------------------------------------------------------------------
'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

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
After being created, I spent too much of my childhood with a Dragon 32. Since then I have worked on Personality software, Children's websites, ATM and transport software. Most hobby development is web based and I often have a iPaq in my hand.

Comments and Discussions

 
GeneralVS6 Version Pin
Davy Mitchell10-May-03 19:48
Davy Mitchell10-May-03 19:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.