Skip to main content

Articles

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Windows Mobile Developer Controls

.NET CF Newsreader using IP*Works!

Written by Lance Robinson  [author's bio]  [read 30697 times]
Edited by Derek

Download the code

Page 1  Page 2 

Arrange articles in treeview

With each firing of the GroupOverview event, I'll use the Message-Id, References, Subject, and From headers to construct a tree. For this, I've dropped a treeview on the form to contain the tree structure. Above the treeview is a combo box for newsgroup names, and below the treeview is a textbox that will be used for displaying the text of the article which is selected in the treeview.

In order to construct the tree, I wrote a subroutine called AddNode which takes as input the article details. The AddNode method adds a new node to the treeview in which the node text is the subject of the message, and the node tag is the message-ID.

In the GroupOverview event, if the references header does not exist, I know that this is a new thread - not a reply. Since this is the case, I can immediately add a new node to the treeview.

If e.References = "" Then 'this message has no references, it is not a reply, start a new thread: AddNode(e.Subject, e.MessageId, TreeView1)

If not, I know that this message is not the beginning of a thread, but a reply. That means I'll need to find where in the tree this message belongs. To do this, I'll search through the tree recursively until I find the treenode in which the messageId matches the last reference of the current message. For this, I've created a GetLastReferenceID function which simply extracts the last message ID from the supplied references header. I've also created a FindPlace function which searches the treeview for that specific last message reference. If I find such a treenode, then I will add a new node as a child of that node. If such a treenode is not found - then that means the message I'm looking at is in response to an older message which has not been downloaded. In this case, we'll just append a new node to the tree.


        Else
            'this message refers to an earlier message
            found = False
			Dim thisref As String = GetLastReferenceID(e.References)
            Dim place As TreeNode = FindPlace(thisref, TreeView1)
            If (found = True) Then
                'add node to existing tree
                AddNode(e.Subject, e.MessageId, place)
            Else
                'or create new thread b/c reference is too old
                AddNode(e.Subject, e.MessageId, TreeView1)
            End If
        End If
    End Sub

Note: For the code above, I have overloaded the AddNode and FindPlace functions to accept a Treeview object as its last parameter, or a Treenode object as its last parameter.

After all of the GroupOverview events have fired, the treeview will be fully populated with the most recent 100 articles

Displaying Article Text

Now that I've got a complete treeview, I want to provide a method so that when a particular tree node is clicked on, that articles text is displayed. In order to display the article, I'll have to download it from the server. To do this, I'll need the message-ID of the article. This is the reason why I've added the message-ID to the treenode tag property in the AddNode method. When a particular node is clicked on, I can simply take that nodes tag property and pass it to the NNTP component's CurrentArticle property. Then just use the NNTP FetchArticle method to connect to the NNTP server and download the article. The article text will then be stored in the NNTP object's ArticleText property.


Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles _
TreeView1.AfterSelect 'get the reference id of select message Dim refid As String refid = TreeView1.SelectedNode.Tag Nntp1.CurrentArticle = refid 'now fetch the article and display StatusBar1.Text = "Downloading article..." Nntp1.FetchArticle() txtArticle.Text = Nntp1.ArticleText StatusBar1.Text = "" End Sub

 

A news reader for embedded devices only scratches the surface of the possibilities with IP*Works! This application can easily be modified to allow the user to compose replies (including html, embedded images, and file attachments) and post them to the news server. All that is necessary is to include the correct references header (if any) in the post. The application also could be modified to connect with SSL-secured NNTP servers, using the NNTPS component in the SSL Edition. The NNTP component is just one of the many components included in the CE Editions, providing plenty of opportunity to come up with new ideas and new applications for CE devices.

 

Previous Page