|
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Text;
using System.IO;
using System.Xml;
namespace CodeProjectDownload
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
//get the RSS from the CodeProject
Uri u=new Uri(@"http://www.codeproject.com/webservices/articlerss.aspx");
HttpWebRequest hwr=(HttpWebRequest)HttpWebRequest.CreateDefault(u);
HttpWebResponse hwre=(HttpWebResponse)hwr.GetResponse();
Stream s= hwre.GetResponseStream();
Byte[] read = new Byte[512];
int bytes = s.Read(read, 0, 512);
StringBuilder sb=new StringBuilder();
while(bytes>0){
Encoding encode =Encoding.GetEncoding("utf-8");
sb.Append(encode.GetString(read,0,bytes));
bytes = s.Read(read, 0, 512);
}
XmlDataDocument xd=new XmlDataDocument();
xd.LoadXml(sb.ToString());
XmlNodeList xnl=xd.DocumentElement.GetElementsByTagName("item");
ItemCodeProjectCollection icpcol=new ItemCodeProjectCollection();
foreach(XmlNode xn in xnl){
ItemCodeProject icp=new ItemCodeProject();
icp.Title= xn.SelectSingleNode("title").InnerText;
icp.Description=xn.SelectSingleNode("description").InnerText;
icp.Url=xn.SelectSingleNode("link").InnerText;
icpcol.Add(icp);
}
string x=icpcol.LinksStartPage();
StringBuilder sbContents=new StringBuilder(ItemCodeProjectCollection.FirstContent());
sbContents.Append(icpcol.LinksStartPage());
sbContents.Append(ItemCodeProjectCollection.LastContent());
Response.Buffer=true;
Response.ContentType="text/xml";
//Response.SuppressContent=true;
Response.Write(sbContents.ToString());
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
#region Helper classes
public class ItemCodeProject{
#region Constructors
public ItemCodeProject():this("","",""){
}
public ItemCodeProject(string TheTitle,string TheDescription,string TheUrl){
Title=TheTitle;
Description=TheDescription;
Url=TheUrl;
}
#endregion
#region properties
#region property Title
public string Title{
get{
return _Title;
}
set{
_Title = value;
}
}string _Title;
#endregion
#region property Description
public string Description{
get{
return _Description;
}
set{
_Description = value;
}
}string _Description;
#endregion
#region property Url
public string Url{
get{
return _Url;
}
set{
_Url = value;
}
}string _Url;
}
#endregion
#endregion
public class ItemCodeProjectCollection : ArrayList {
protected Hashtable innerHash;
public ItemCodeProjectCollection() {
//TODO : make the costructor with the URI
}
#region Code Project Methods
public string LinksStartPage(){
string LinkGroup="CodeProject";
StringBuilder sb=new StringBuilder();
sb.Append("\t<Context>");
sb.Append("\t\t<Links>");
int iNumber=1;
string sLink=LinkGroup=" LinkGroup=\"" + LinkGroup + "\"";
foreach(ItemCodeProject icp in this){
sb.Append("\t\t\t<LItemEx>");
sb.Append("\t\t\t\t<LItem ");
sb.Append("ID=" + "\"" + "LI"+ iNumber.ToString()+ "\"");
sb.Append(sLink);
sb.Append(" Image=\"http://www.codeproject.com/images/codeproject88x31.gif\" ");
sb.Append(" URL=\""+icp.Url+"\"");
sb.Append(">");
sb.Append(icp.Title);
sb.Append("");
sb.Append("\t\t\t\t</LItem>");
sb.Append("<Blurb>");
sb.Append(icp.Description);
sb.Append("</Blurb>");
sb.Append("\t\t\t</LItemEx>");
iNumber++;
}
sb.Append("\t\t</Links>");
sb.Append("\t</Context>");
return sb.ToString();
}
public static string FirstContent(){
StringBuilder sb=new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
sb.Append("<TabDefinition>");
sb.Append("<Tab ID=\"live_tab\" Name=\"Live\" Filterable=\"true\">");
sb.Append("<Application ID=\"Live_App\">");
sb.Append("<Pane ID=\"Main_Pane\">");
sb.Append("<Break/>");
sb.Append("<TextSpan ID=\"Tab_Description\" FontSize=\"16\"> Code Project Links</TextSpan> <Break/>");
sb.Append("<Break/>");
sb.Append("<Hyperlink ID=\"CodeProjectURL\" URL=\"http://www.codeproject.com\">Open Code Project</Hyperlink>");
sb.Append("<Break/>");
sb.Append("<Hyperlink ID=\"CodeProjectURLRSS\" URL=\"http://www.codeproject.com/webservices/articlerss.aspx\">Code Project RSS</Hyperlink>");
sb.Append("<Break/>");
sb.Append("<Hyperlink ID=\"Author\" URL=\"http://www.fortunecity.com/tattooine/slaine/226/vb/home.htm\">Author Web Page</Hyperlink>");
sb.Append("<Break/>");
sb.Append("<HRule/>");
sb.Append("<LinkGroupSet>");
sb.Append("<LinkGroup ID=\"CodeProject\" Title=\"RECENT CODE PROJECT LINKS\">");
sb.Append(" </LinkGroup>");
sb.Append(" </LinkGroupSet>");
sb.Append("</Pane>");
sb.Append("<Data>");
return sb.ToString();
}
public static string LastContent(){
StringBuilder sb=new StringBuilder("</Data>");
sb.Append("</Application>");
sb.Append("</Tab>");
sb.Append("</TabDefinition>");
return sb.ToString();
}
#endregion
}
#endregion
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.