protected void Page_Load(object sender, EventArgs e) { GenericRssChannel c = GenericRssChannel.LoadChannel("http://rss.msnbc.msn.com/id/3032091/device/rss/rss.xml"); Image1.ImageUrl = c.Image["url"]; GridView1.DataSource = c.SelectItems(); GridView1.DataBind(); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { GenericRssChannel c = GenericRssChannel.LoadChannel(feedLocation); int recordCount = c.Items.Count; if (recordCount == 0) { //if we didn't find anything, add a message literal and drop out. Literal messageLiteral = new Literal(); messageLiteral.Text = NoItemsFoundText; this.Controls.Add(messageLiteral); return; } //limit the number of records to show if needed. if (MaxRecords > 0 && MaxRecords < recordCount) { recordCount = MaxRecords; } HtmlTable table = new HtmlTable(); table.CellPadding = 2; table.CellSpacing = 2; table.Border = 0; for (int i = 0; i < recordCount; i++) { HtmlTableRow row = new HtmlTableRow(); HtmlTableCell cell = new HtmlTableCell(); HyperLink link = new HyperLink(); link.NavigateUrl = c.Items[i]["link"]; link.Text = c.Items[i]["title"]; if (separateItems) { link.Font.Bold = true; } if (Target.Trim().Length > 0) { link.Target = Target; } cell.Controls.Add(link); if (showDate) { try { Literal dateLiteral = new Literal(); dateLiteral.Text = " - Posted: " + DateTime.Parse(c.Items[i]["pubDate"]).ToShortDateString(); cell.Controls.Add(dateLiteral); } catch { } } if (ShowDescription) { HtmlGenericControl div = new HtmlGenericControl("div"); //div.InnerHtml = Server.HtmlEncode(c.Items[i]["description"]); div.InnerHtml = c.Items[i]["description"]; cell.Controls.Add(div); } row.Cells.Add(cell); table.Rows.Add(row); if (separateItems && recordCount > 1 && i < recordCount - 1) { HtmlTableRow ruleRow = new HtmlTableRow(); HtmlTableCell ruleCell = new HtmlTableCell(); HtmlGenericControl rule = new HtmlGenericControl("hr"); rule.Style.Add("width", "99%"); ruleCell.Controls.Add(rule); ruleRow.Cells.Add(ruleCell); table.Rows.Add(ruleRow); } } this.Controls.Add(table); } catch (Exception ex) { Literal messageLiteral = new Literal(); if (DebugUtility.IsDebugMode(Response, Request)) { messageLiteral.Text = "The following error occurred while checking the rss feed:<br /><br />"; messageLiteral.Text += "<b>Message:</b> " + ex.Message + "<br /><br />" + "<b>Stack Trace:</b> " + ex.StackTrace.Replace("\n", "<br />"); } else { messageLiteral.Text = NoItemsFoundText; } this.Controls.Add(messageLiteral); } }
static void Main(string[] args) { Console.WriteLine("Simple RSS Compiler v1.0"); Console.WriteLine(); // Process command line if (args.Length != 2) { Console.WriteLine("usage: rssdl.exe url-or-file outputcode.cs"); return; } string url = args[0]; string codeFilename = args[1]; string classNamePrefix = Path.GetFileNameWithoutExtension(codeFilename); // Load the channel data from supplied url GenericRssChannel channel; try { // try to interpret as file first bool isFile = false; try { if (File.Exists(url)) { isFile = true; } } catch { } if (isFile) { XmlDocument doc = new XmlDocument(); doc.Load(url); channel = GenericRssChannel.LoadChannel(doc); } else { channel = GenericRssChannel.LoadChannel(url); } } catch (Exception e) { Console.WriteLine("*** Failed to load '{0}' *** {1}: {2}", url, e.GetType().Name, e.Message); return; } // Open the output code file TextWriter codeWriter; try { codeWriter = new StreamWriter(codeFilename, false); } catch (Exception e) { Console.WriteLine("*** Failed to open '{0}' for writing *** {1}: {2}", codeFilename, e.GetType().Name, e.Message); return; } // Get the language from file extension string lang = Path.GetExtension(codeFilename); if (lang != null && lang.Length > 1 && lang.StartsWith(".")) { lang = lang.Substring(1).ToUpperInvariant(); } else { lang = "CS"; } // Generate source try { RssCodeGenerator.GenerateCode(channel, lang, "", classNamePrefix, codeWriter); } catch (Exception e) { codeWriter.Dispose(); File.Delete(codeFilename); Console.WriteLine("*** Error generating '{0}' *** {1}: {2}", codeFilename, e.GetType().Name, e.Message); return; } // Done codeWriter.Dispose(); Console.WriteLine("Done -- generated '{0}'.", codeFilename); }
private void BindRssNews() { string ss = ""; string RssPath = (Request["RssPath"] == null) ? "" : Request["RssPath"].ToString(); int RssCount = (Request["RssCount"] == null) ? 0 : int.Parse(Request["RssCount"].ToString()); if (RssPath != "") { RssDataSource rss = new RssDataSource(); GenericRssChannel channel = new GenericRssChannel(); try { rss.Url = RssPath; rss.DataBind(); channel = rss.Channel; } catch { Response.ContentType = "text/xml"; Response.Write("<div style='text-align:center;padding:10px;color:red;' class='text'>" + LocRM.GetString("tRSSProblems") + "</div>"); return; } //XMLUtilities // Create root element XmlDocument doc = new XmlDocument(); XmlNode root = doc.AppendChild(doc.CreateElement("rssData")); XmlNode node = doc.CreateElement("htmlData"); StringBuilder sb = new StringBuilder(); sb.AppendFormat("<div>"); sb.AppendFormat("<div style='padding-top: 3px;padding-bottom:3px;color: #444;font-size: 10pt;'><b>{0}</b></div>", channel.Attributes["Title"]); for (int i = 0; i < channel.Items.Count && i < RssCount; i++) { sb.AppendFormat("<div style='padding-top: 3px;' class='text'><a href='{1}' target='_blank'>{0}</a></div>", channel.Items[i].Attributes["Title"], channel.Items[i].Attributes["Link"]); sb.AppendFormat("<div style='color: gray;' class='text'>{0}</div>", Convert.ToDateTime(channel.Items[i].Attributes["pubDate"]).ToString()); //sb.AppendFormat("<div style='color: black; font-family: tahoma; font-size: 12px;'>{0}</div>", channel.Items[i].Attributes["description"]); } sb.Append("</div>"); XmlNode cdata = doc.CreateCDataSection(sb.ToString()); //node.Name = "htmlData"; node.AppendChild(cdata); root.AppendChild(node); //doc.DocumentElement.AppendChild(doc.CreateCDataSection(sb.ToString())); ss += doc.InnerText; } Response.ContentType = "text/xml"; Response.Write(ss); }