using System; using System.Collections.Generic; using System.Web; using System.IO; using System.Net; using System.Text; /* @Author: Gaurav Pandey (gaurav@caa.columbia.edu) @Description: Part of Gaurav's personal Web Site to fetch Wordpress Blog Articles */ class BlogEntity { public string title; public string link; } class BlogData { public string GetData() { // // TODO: Add constructor logic here // String finalString = string.Empty; List titles = new List(); List links = new List(); List entityList = new List(); string defaultURL = "http://gauravpandey.com/wordpress/?p="; using (WebClient client = new WebClient()) { using (Stream myStream = client.OpenRead("http://gauravpandey.com/wordpress/?feed=rss2")) { using (StreamReader reader = new StreamReader(myStream)) { String data = string.Empty; while ((data = reader.ReadLine()) != null) { if (data.Contains("") && !data.Contains("Weblog")) { titles.Add(data.Replace("<title>", string.Empty).Replace("", string.Empty).Trim()); } else if (data.Contains(defaultURL) && data.Contains("") && data.Contains("")) { links.Add(data.Replace("", string.Empty).Replace("", string.Empty).Trim()); } else { //all the remaining garbage data } } } } } int len = titles.Count; for (int i = 0; i < len; i++) { BlogEntity objX = new BlogEntity(); objX.title = titles[i]; objX.link = links[i]; entityList.Add(objX); } titles.Clear(); titles = null; links.Clear(); links = null; StringBuilder sbX = new StringBuilder(); sbX.Append("Recent blog articles by Gaurav from Wordpress >> "); foreach (BlogEntity x in entityList) { sbX.Append(string.Format("{1}      ", x.link, x.title)); } return sbX.ToString(); } }