RSS Feed from an Access Database



Similar documents
Deploying Migrated IBM Notes Applications to the Cloud

R i o L i n x s u p p o r r i o l i n x. c o m 1 / 3 0 /

Tutorial #1: Getting Started with ASP.NET

Layer2 Business Data List Connector for SharePoint

MS Enterprise Library 5.0 (Logging Application Block)

How to Use PIPS Access to/from SQL Database Utility Program. By PIPSUS Support Team Dr. Chouikha

Migrating helpdesk to a new server

Polar Help Desk Installation Guide

To install Multifront you need to have familiarity with Internet Information Services (IIS), Microsoft.NET Framework and SQL Server 2008.

USER GUIDE Deploying Your Application to WinHost

Sitecore Ecommerce Enterprise Edition Installation Guide Installation guide for administrators and developers

Connect to MySQL or Microsoft SQL Server using R

Eylean server deployment guide

Microsoft SQL Server Express 2005 Install Guide

ReportBy Notification Examples

Subscribe to RSS in Outlook Find RSS Feeds. Exchange Outlook 2007 How To s / RSS Feeds 1of 7

Table of Contents SQL Server Option

Microsoft Exam MB2-702 Microsoft Dynamics CRM 2013 Deployment Version: 6.1 [ Total Questions: 90 ]

GETTING STARTED WITH SQL SERVER

Deploying Your Website Using Visual Studio. Deploying Your Site Using the Copy Web Site Tool

Crystal Reports. For Visual Studio.NET. Reporting Off ADO.NET Datasets

Click Studios. Passwordstate. High Availability Installation Instructions

FTP, IIS, and Firewall Reference and Troubleshooting

Download and Installation of MS SQL Server

SelectSurvey.NET Developers Manual

MONAHRQ Installation Permissions Guide. Version 2.0.4

Reference and Troubleshooting: FTP, IIS, and Firewall Information

INTRODUCTION: SQL SERVER ACCESS / LOGIN ACCOUNT INFO:

Installing the MySQL ODBC Connector Windows XP and Windows 7. Roth Technologies, LLC

1.264 Lecture 19 Web database: Forms and controls

TechTips. Connecting Xcelsius Dashboards to External Data Sources using: Web Services (Dynamic Web Query)

Microsoft Windows Shared Hosting Seminar. DotNetNuke Technical Overview. May/June 2005

Creating Form Rendering ASP.NET Applications

Composite C1 Load Balancing - Setup Guide

Mobil . Administrator s Guide Citrix Systems, Inc. All rights reserved.

Dashboard Admin Guide

PDshop.NET Installation Guides (ASP.NET Edition)

A Java proxy for MS SQL Server Reporting Services

Quartz.Net Scheduler in Depth

Millennium Drive. Installation Guide

GoDaddy (CentriqHosting): Data driven Web Application Deployment

Migration Instructions for MS Dynamics CRM

ibolt V3.2 Release Notes

Click Studios. Passwordstate. High Availability Installation Instructions

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Click Studios. Passwordstate. Installation Instructions

SelectSurvey.NET IT Staff Training

How to set up Outlook Anywhere on your home system

Analytics Configuration Reference

Adding ELMAH to an ASP.NET Web Application

NetSupport DNA Configuration of Microsoft SQL Server Express

ASP.NET Using C# (VS2012)

nopcommerce User Guide

Hands-On Lab. Web Development in Visual Studio Lab version: Last updated: 12/10/2010. Page 1

Linking Access to SQL Server

MS SQL Express installation and usage with PHMI projects

ODBC Client Driver Help Kepware, Inc.

Visual COBOL ASP.NET Shopping Cart Demonstration

Team Quicken Loans: Mobile RFID Inventory Tracking System. Administrator Manual

Kentico CMS 7.0 Windows Azure Deployment Guide

Click Studios. Passwordstate. Upgrade Instructions to V7 from V5.xx

Walkthrough: Creating and Using an ASP.NET Web Service in Visual Web Developer

One method for batch DHI data import into SQL-Server. A batch data import technique for DateSet based on.net Liang Shi and Wenxing Bao

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

One Bing Maps application ID was used to make requests to two different sets of URLs, one for staging and one for production.

Sage Intelligence Financial Reporting for Sage ERP X3 Version 6.5 Installation Guide

Crystal Reports for Visual Studio.NET

WordPress & RSS: What You Need to Know

HarePoint Workflow Extensions Manual. For SharePoint Server 2013, SharePoint Server 2010, SharePoint Foundation 2013 and SharePoint Foundation 2010.

Implementing and Maintaining Microsoft SQL Server 2008 Integration Services

AD Phonebook 2.2. Installation and configuration. Dovestones Software

How To Install A New Database On A 2008 R2 System With A New Version Of Aql Server 2008 R 2 On A Windows Xp Server 2008 (Windows) R2 (Windows Xp) (Windows 8) (Powerpoint) (Mysql

Installing OGDI DataLab version 5 on Azure

FaxCore 2007 Database Migration Guide :: Microsoft SQL 2008 Edition

Sitecore Security Hardening Guide

Jet Data Manager 2012 User Guide

McAfee One Time Password

HTTP - METHODS. Same as GET, but transfers the status line and header section only.

Expanded contents. Section 1. Chapter 2. The essence off ASP.NET web programming. An introduction to ASP.NET web programming

Security Assertion Markup Language (SAML) Site Manager Setup

Installation / Backup \ Restore of a Coffalyser.Net server database using SQL management studio

E-Commerce: Designing And Creating An Online Store

SQL Injection Vulnerabilities in Desktop Applications

Connecticut Hazardous Waste Manifests Database

Integration Microsoft Dynamics CRM with SharePoint and Office 365 via OData

Continuous integration for databases using

Global Search v.2.8 for Microsoft Dynamics CRM 4.0

BUILDER 3.0 Installation Guide with Microsoft SQL Server 2005 Express Edition January 2008

HP Project and Portfolio Management Center

What s New: Crystal Reports for Visual Studio 2005

New Features in Neuron ESB 2.6

Exchange Server 2003 Management Pack Guide for Operations Manager 2007

Engagement Analytics Configuration Reference Guide

Synchronization with Microsoft Team Foundation Server 2010

Transcription:

RSS Feed from an Access Database Scott Savage (2005) RSS stands for Really Simple Syndication and it is the latest way to keep up to date on the internet. Essentially it is an XML feed that contains data such as headlines which provides a summary of an information update. In this example I will be showing you how to use an Access Database which stores news stories. In this example I will be using Visual Web Developer 2005 Express Edition. This is a free download from Microsoft and is a very comprehensive and user friendly package for anyone looking to write.net web applications. The first step is to create a new web site in which to write our code. You may already have an existing web site, and if this is the case then just insert a new.aspx file into your current web site. We will be doing all our coding today in the source view window as shown below. As you can see I am going to put my code in the code behind file called Default.aspx.cs. I like the way Visual Studio separates your code into presentation layers into these 2 files. In our case however there will be very little going into the presentation layer (Default.aspx). This example also assumes that you have already created an Access database which is located in the App_Data directory within your website. This database is called news.mdb in my case and should have the following fields:

Field Name Field Type Field Description Newsid Number Primary key for the news articles Headline Text Stores the headline for the news article Date Date/Time Stores the time and date that the news article was published. Body Text Stores the body of the news article Notice that when you create a new aspx file the code sits in the code behind file, in this case it is called Default.aspx.cs (because I am programming in C#). This is also a good shot of the Express Edition interface. It is almost identical to the Visual Studio 2005 interface and contains all the critical features. In fact I am yet to find a single feature that I need and is not present. I strongly advise anyone looking to dip their toes into.net to download this software before Microsoft starts charging for it in a year or so. We next need to configure the database connection string. The best place to do this is in the web.config file. If you have already compiled the project for the first time a basic web.config will have already been generated for you. You can

just modify the file (which is in XML) to add in the <connectionstring> information. This is a better place to store the connection string as it can be reused for all your database connections. If you change the database or the database authentication information for example then there is a central place to modify the code. We then use this connection string to connect to the database. In this case as we are connecting to an Access database we use the OleDb connection methods. These would change based on what type of database you want to connect to (or XML source). In our SELECT query we are just selecting all the data from the news rows. In practice we would probably limit the number of results returned. The number of results to return varies, but I would suggest 10-15 is probably a good number.

//get the connection string from web.config string connectionstring = ConfigurationManager.ConnectionStrings["NewsConnectionString"].Connect ionstring; //open the database connection OleDbConnection OleDbConnection1 = new OleDbConnection(connectionString); OleDbConnection1.Open(); // Now the Select statement you want to run string select = "SELECT * FROM news ORDER BY Date"; OleDbDataAdapter oleda = new OleDbDataAdapter(select, OleDbConnection1); There are a number of headers required for setting up an RSS feed as defined in the RSS 2.0 standard. In our case we also need to setup the HTTP headers so we are responding to the HTTP request with XML. We then use the XMLTextWriter which helps us output some neat XML code for our response. // Set the content-type to XML Response.ContentType = "text/xml"; // Use an XmlTextWriter to write the XML data to a string XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); // start the document writer.writestartdocument(); // write out <rss version="2.0"> writer.writestartelement("rss"); writer.writeattributestring("version", "2.0"); // write out <channel> writer.writestartelement("channel"); // write out <channel>-level elements writer.writeelementstring("title", "My News Site"); writer.writeelementstring("link", "http://www.mynewssite.com/"); writer.writeelementstring("description", "My News RSS Feed"); //writer.writeelementstring("ttl", "60"); writer.writeelementstring("docs","http://blogs.law.harvard.edu/tech/rs s");

Next we write out the block of XML for each news article, which is essentially the bulk of the feed. Note that the fields follow the RSS 2.0 standard set out by Harvard University. This standardisation is necessary to ensure your RSS feed is readable by 3 rd party clients. //loop through the articles and output the XML data foreach (DataTable mytable in newsdata.tables) { foreach (DataRow myrow in mytable.rows) { // write out <item> writer.writestartelement("item"); // write out <item>-level information writer.writeelementstring("title", Convert.ToString(myrow["Headline"])); // direct link to the news article writer.writeelementstring("link", "http://www.mynewssite.com/news.aspx?" + myrow["newsid"]); // the body of the news article (may need a word limit) writer.writeelementstring("description", Convert.ToString(myrow["Body"])); // the author of the news article writer.writeelementstring("author", "scott@kgbnetworks.com (Scott Savage)"); // the publish date (formatted according to RFC 822) writer.writeelementstring("pubdate", Convert.ToString(myrow["Date"])); } } // close the item tag </item> writer.writeendelement(); We have finished writing out the news articles, so it is time to clean up. We have a few elements to close off as well as closing the actual document and the HTTP response.

// clean up after we are finished with the database OleDbConnection1.Close(); // write out </channel> writer.writeendelement(); // write out </rss> writer.writeendelement(); // finish writing the document writer.writeenddocument(); // Flush and close the writer writer.flush(); writer.close(); Response.End(); This leaves us with an XML document that contains all the latest news articles for your website. An important point to note is that a URL is needed so that when a client is interested in your news article they can click a link to be taken straight there. No-one wants a link to your home page only to have to then search for the article. This will probably require you to create an additional page. One of the best things about.net is the ease with which you can modify code if a data source changes. If you would prefer to use an SQL Server or MySQL (via ODBC) database for example, the code changes are very minimal. Even using an XML data source would be a minor change. The advantage of this for a number of students, including myself, is that re-writing your front-end code in.net does not require an immediate migration of your backend (from MySQL to SQL Server for example). This kind of phased implementation is a great way to learn a lot about.net technology without throwing yourself into the deep end. With the release of IE7 and Microsoft s continued focus on web services you can be sure that your work on RSS will not go unrewarded. Content is critical to the success of any website, and a good RSS feed keeps your viewers coming back.