RSS reader (using rsstoolkit for Asp.net 2.0)

Source: Internet
Author: User

(1) Add a web form "complexrss" under the root directory of the website ".

(2) switch to the design view, drag a "gridview" control to the interface, and design its style. The specific style is as follows:CodeSee Figure 5-4. Because the data source binding technology is used, you do not need to configure the data source for the "gridview" control.

<Asp: gridview id = "gridview1" runat = "server" cellpadding = "4" forecolor = "#333333" gridlines = "NONE">

<Footerstyle backcolor = "# 5d7b9d" font-bold = "true" forecolor = "white"/>

<Rowstyle backcolor = "# f7f6f3" forecolor = "#333333"/>

<Editrowstyle backcolor = "#999999" type = "regxph" text = "yourobjectname"/>

<Selectedrowstyle backcolor = "# e2ded6" font-bold = "true" forecolor = "#333333"/>

<Pagerstyle backcolor = "#284775" forecolor = "white" horizontalalign = "center"/>

<Headerstyle backcolor = "# 5d7b9d" font-bold = "true" forecolor = "white"/>

<Alternatingrowstyle backcolor = "white" forecolor = "#284775"/>

</ASP: gridview>

(3) After the interface is designed, you need to write the code to bind it. At this time, you need to use the RSS tool class library and add it to this site. Right-click the root directory of the website and choose add reference from the shortcut menu. The add reference dialog box is displayed, as shown in Figure 5-12.

(4) switch to the Browse tab, as shown in Figure 5-13.

(5) through the "search range" drop-down box, find the RSS tool folder "RssToolkit-1-0-0-1", select the folder "bin", select the file "rsstoolkit. dll ".

(6) Click "OK". A "bin" folder is added under the root directory of the website, which contains a file named "rsstoolkit. dll ".

(7) the class file has been referenced, and the method provided by the class is used now. Press F7 to go to the Code interface on the "complexrss" page.
(8) You must first Add a reference to the namespace where the RSS tool is located. The syntax is "using rsstoolkit ;".

(9) In the "page_load" event, call the RSS tool to bind the control data source to the gridview. The specific implementation code is shown in Figure 5-5.

Using rsstoolkit;

Public partial class complexrss: system. Web. UI. Page

{

Protected void page_load (Object sender, eventargs E)

{

// Create a channel

Genericrsschannel c = genericrsschannel. loadchannel ("http://blog.csdn. Net/championchen79/category/197094. aspx/RSS ");

// Bind a data source to the gridview

// The Data Source comes from all projects in the Channel

Gridview1.datasource = C. selectitems ();

Gridview1.databind ();

}

}

(10) press Ctrl + S to save the design.

(11) set this page as the start page and press F5 to runProgramTo test whether the grid-bound channel list is properly navigated. The final running interface is 5-14.

 

5.4.4 allow the site to provide the subscription function

The RSS toolkit provides two controls in total. One is "rssdatasource", which has been introduced in the simple reader example; the other is "rsshyperlink ", this control is mainly used to provide the subscription function for the site. This section describes the control to gradually complete the site subscription function. The specific steps are as follows.

(1) to implement the subscription function on the site, you must provide a list of functions that allow users to subscribe to. This section describes how to manually write two channels. The content provided is the RSS subscription of the two previously created readers.

(2) Add a "general handler" file under the root directory of the website and name it "sample. ashx ". The handler mainly uses the Web processing class inherited from the "ihttphandler" interface to convert various files and let the web application recognize these files.

(3) The processing interface used in this example is provided by the RSS tool. Therefore, you must reference the tool's namespace "rsstoolkit" in the file and add the processing content of the channel, see Code List 5-6. There is a channel and two items in the list.

<% @ Webhandler Language = "C #" class = "sample" %>

Using system;

Using system. Web;

Using rsstoolkit;

Public class sample: genericrsshttphandlerbase

{

Protected override void populatechannel (string channelname, string username)

{

// Add a channel

Channel ["title"] = "sample channel ";

// If the channel name is not blank

If (! String. isnullorempty (channelname ))

{

// Set the channel name

Channel ["title"] + = "'" + channelname + "'";

}

// If the access user name is not blank

If (! String. isnullorempty (username ))

{

// Set the user name

Channel ["title"] + = "(generated for" + username + ")";

}

// Set other default channel attributes

// Here is the RSS of the simple Reader

Channel ["Link"] = "~ /Default. aspx ";

Channel ["Description"] = "channel for test in ASP. net rss ";

Channel ["TTL"] = "10 ";

Channel ["name"] = channelname;

Channel ["user"] = username;

// Define items

Genericrsselement item;

// Create an item in a channel

Item = new genericrsselement ();

// Assign a value to the basic attribute of the item

Item ["title"] = "complex ";

Item ["Description"] = "complex RSS using rssdatasource ";

Item ["Link"] = "~ /Complexrss. aspx ";

// Add the item to the Channel

Channel. Items. Add (item );

 

// Create an item in a channel

Item = new genericrsselement ();

// Assign a value to the basic attribute of the item

Item ["title"] = "simple ";

Item ["Description"] = "simple RSS is tested ";

Item ["Link"] = "~ /Simplereader. aspx ";

// Add the item to the Channel

Channel. Items. Add (item );

}

}

(4) Open the "default. aspx" Page and drag an "rsshyperlink" control to the design view.

(5) press the F4 key to display its Properties window, and change the property "navigateurl" to "~ /Sample. ashx ".

(6) press Ctrl + S to save all designs.

(7) Press F5 to run the program and test the website subscription function.

Download Tool

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.