ASP.NET 生成 RSS Feed

前段时间在写RSS Feed。 
 经过了几次的修改,把相关的代码写成了单独的类。 
 感觉重用时还算比较方便的。于是贴出来,大家一起研究研究。
  1 None.gif using  System; 
  2 None.gif using  System.Collections.Generic; 
  3 None.gif using  System.Xml; 
  4 None.gif    
  5 None.gif    namespace  MyMedia.Utilities 
  6 ExpandedBlockStart.gifContractedBlock.gif    dot.gif
  7InBlock.gif    public class RssBase 
  8ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif
  9InBlock.gif    
 10ContractedSubBlock.gifExpandedSubBlockStart.gif       RssBase constructor#region RssBase constructor 
 11InBlock.gif       public RssBase(XmlTextWriter rssWriter) 
 12ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
 13InBlock.gif        this.rssWriter = rssWriter; 
 14ExpandedSubBlockEnd.gif       }
 
 15InBlock.gif       public RssBase(XmlTextWriter rssWriter, bool hasMedia, IList<ItemInfo> items) 
 16ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
 17InBlock.gif           this.rssWriter = rssWriter; 
 18InBlock.gif           this.hasMedia = hasMedia; 
 19InBlock.gif           this.items = items; 
 20ExpandedSubBlockEnd.gif       }
 
 21ExpandedSubBlockEnd.gif       #endregion
 
 22InBlock.gif       
 23InBlock.gif       [Serializable] 
 24InBlock.gif       public sealed class ItemInfo 
 25ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
 26InBlock.gif       
 27ContractedSubBlock.gifExpandedSubBlockStart.gif       ItemInfo constructor#region ItemInfo constructor 
 28ExpandedSubBlockStart.gifContractedSubBlock.gif       public ItemInfo() dot.gif{ } 
 29InBlock.gif       public ItemInfo(string itemTitle, string itemLink, string itemDescription, string itemPubDate, string itemAuthor, string itemGuid) 
 30ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
 31InBlock.gif           this.itemTitle = itemTitle; 
 32InBlock.gif           this.itemLink = itemLink; 
 33InBlock.gif           this.itemDescription = itemDescription; 
 34InBlock.gif           this.itemAuthor = itemAuthor; 
 35InBlock.gif           this.itemGuid = itemGuid; 
 36InBlock.gif           this.itemPubDate = itemPubDate; 
 37ExpandedSubBlockEnd.gif       }
 
 38InBlock.gif       public ItemInfo(string itemTitle, string itemLink, string itemDescription, string itemPubDate, string itemAuthor,string itemGuid, string mediaContentUrl, string mediaTitle, string mediaDescription,string mediaThumbUrl, string mediaThumbWidth, string mediaThumbHeight, string mediaAuthor) 
 39ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
 40InBlock.gif           this.itemTitle = itemTitle; 
 41InBlock.gif           this.itemLink = itemLink; 
 42InBlock.gif           this.itemDescription = itemDescription; 
 43InBlock.gif           this.itemPubDate = itemPubDate; 
 44InBlock.gif           this.itemAuthor = itemAuthor; 
 45InBlock.gif           this.itemGuid = itemGuid; 
 46InBlock.gif           this.mediaContentUrl = mediaContentUrl; 
 47InBlock.gif           this.mediaTitle = mediaTitle; 
 48InBlock.gif           this.mediaDescription = mediaDescription; 
 49InBlock.gif           this.mediaThumbUrl = mediaThumbUrl; 
 50InBlock.gif           this.mediaThumbWidth = mediaThumbWidth; 
 51InBlock.gif           this.mediaThumbHeight = mediaThumbHeight; 
 52InBlock.gif           this.mediaAuthor = mediaAuthor; 
 53ExpandedSubBlockEnd.gif       }
 
 54ExpandedSubBlockEnd.gif       #endregion
 
 55InBlock.gif       
 56InBlock.gif      
 57ContractedSubBlock.gifExpandedSubBlockStart.gif       Internal item variables#region Internal item variables 
 58InBlock.gif       // Item variables 
 59InBlock.gif        private string itemTitle; 
 60InBlock.gif        private string itemLink; 
 61InBlock.gif        private string itemDescription; 
 62InBlock.gif        private string itemPubDate = DateTime.Now.ToString("r"); 
 63InBlock.gif        private string itemDateTaken = DateTime.Now.ToString(); 
 64InBlock.gif        private string itemAuthor; 
 65InBlock.gif        private string itemGuid; 
 66InBlock.gif        // Media variables 
 67InBlock.gif        private string mediaContentUrl; 
 68InBlock.gif        private string mediaTitle; 
 69InBlock.gif        private string mediaDescription; 
 70InBlock.gif        private string mediaThumbUrl; 
 71InBlock.gif        private string mediaThumbWidth; 
 72InBlock.gif        private string mediaThumbHeight; 
 73InBlock.gif        private string mediaAuthor; 
 74ExpandedSubBlockEnd.gif        #endregion
 
 75InBlock.gif        
 76ContractedSubBlock.gifExpandedSubBlockStart.gif       Item properties#region Item properties 
 77InBlock.gif
 78InBlock.gif        public string ItemTitle 
 79ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
 80ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ itemTitle = value; } 
 81ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn itemTitle; } 
 82ExpandedSubBlockEnd.gif        }
 
 83InBlock.gif        public string ItemLink 
 84ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
 85ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ itemLink = value; } 
 86ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn itemLink; } 
 87ExpandedSubBlockEnd.gif        }
 
 88InBlock.gif        public string ItemDescription 
 89ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
 90ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ itemDescription = value; } 
 91ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn itemDescription; } 
 92ExpandedSubBlockEnd.gif        }
 
 93InBlock.gif        public string ItemPubDate 
 94ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
 95ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ itemPubDate = value; } 
 96ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn itemPubDate; } 
 97ExpandedSubBlockEnd.gif        }
 
 98InBlock.gif        public string ItemDateTaken 
 99ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif
100ExpandedSubBlockStart.gifContractedSubBlock.gif            set dot.gif{ itemDateTaken = value; } 
101ExpandedSubBlockStart.gifContractedSubBlock.gif            get dot.gifreturn itemDateTaken; } 
102ExpandedSubBlockEnd.gif       }
 
103InBlock.gif       public string ItemAuthor 
104ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
105ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ itemAuthor = value; } 
106ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn itemAuthor; } 
107ExpandedSubBlockEnd.gif       }
 
108InBlock.gif       public string ItemGuid 
109ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
110ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ itemGuid = value; } 
111ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn itemGuid; } 
112ExpandedSubBlockEnd.gif       }
 
113InBlock.gif       public string MediaContentUrl 
114ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
115ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaContentUrl = value; } 
116ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaContentUrl; } 
117ExpandedSubBlockEnd.gif       }
 
118InBlock.gif       public string MediaTitle 
119ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
120ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaTitle = value; } 
121ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaTitle; } 
122ExpandedSubBlockEnd.gif       }
 
123InBlock.gif       public string MediaDescription 
124ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
125ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaDescription = value; } 
126ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaDescription; } 
127ExpandedSubBlockEnd.gif       }
 
128InBlock.gif       public string MediaThumbUrl 
129ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
130ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaThumbUrl = value; } 
131ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaThumbUrl; } 
132ExpandedSubBlockEnd.gif       }
 
133InBlock.gif       public string MediaThumbWidth 
134ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
135ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaThumbWidth = value; } 
136ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaThumbWidth; } 
137ExpandedSubBlockEnd.gif       }
 
138InBlock.gif       public string MediaThumbHeight 
139ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
140ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaThumbHeight = value; } 
141ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaThumbHeight; } 
142ExpandedSubBlockEnd.gif       }
 
143InBlock.gif       public string MediaAuthor 
144ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
145ExpandedSubBlockStart.gifContractedSubBlock.gif           set dot.gif{ mediaAuthor = value; } 
146ExpandedSubBlockStart.gifContractedSubBlock.gif           get dot.gifreturn mediaAuthor; } 
147ExpandedSubBlockEnd.gif       }
 
148InBlock.gif
149ExpandedSubBlockEnd.gif       #endregion
 
150InBlock.gif       
151ExpandedSubBlockEnd.gif       }
 
152InBlock.gif       
153ContractedSubBlock.gifExpandedSubBlockStart.gif       Const string#region Const string 
154InBlock.gif       private const string TITLE = "MyMedia RSS"
155InBlock.gif       private const string XMLNS_MEDIA = "http://www.MyWii.com.au"
156InBlock.gif       private const string XMLNS_DC = "http://purl.org/dc/elements/1.1/"
157InBlock.gif       private const string LINK = "http://www.MyWii.com.au/"
158InBlock.gif       private const string DESCRIPTION = "description"
159InBlock.gif       private const string LANGUAGE = "en-us"
160InBlock.gif       private const string COPYRIGHT = "Copyright 2006"
161InBlock.gif       private const string GENERATOR = "MyMedia RSS Generator"
162InBlock.gif       private const string IMAGE_URL = "http://edu.itbulo.com/UploadFiles_1485/200608/20060831102017260.gif"
163InBlock.gif       private const string IMAGE_TITLE = "MyWii"
164InBlock.gif       private const string IMAGE_LINK = "http://www.MyWii.com.au"
165InBlock.gif       private string PUB_DATE = DateTime.Now.ToString("r"); 
166InBlock.gif       private string LAST_BUILD_DATE = DateTime.Now.ToString("r"); 
167InBlock.gif       
168ExpandedSubBlockEnd.gif       #endregion
 
169InBlock.gif       
170ContractedSubBlock.gifExpandedSubBlockStart.gif       Internal member variables#region Internal member variables 
171InBlock.gif       private XmlTextWriter rssWriter; 
172InBlock.gif       private bool hasMedia; 
173InBlock.gif       private IList<ItemInfo> items; 
174ExpandedSubBlockEnd.gif       #endregion
 
175InBlock.gif       
176ContractedSubBlock.gifExpandedSubBlockStart.gif       Properties#region Properties 
177InBlock.gif       public XmlTextWriter RssWriter 
178ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
179ExpandedSubBlockStart.gifContractedSubBlock.gif       set dot.gif{ rssWriter = value; } 
180ExpandedSubBlockStart.gifContractedSubBlock.gif       get dot.gifreturn rssWriter; } 
181ExpandedSubBlockEnd.gif       }
 
182InBlock.gif       public bool HasMedia 
183ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
184ExpandedSubBlockStart.gifContractedSubBlock.gif       set dot.gif{ hasMedia = value; } 
185ExpandedSubBlockStart.gifContractedSubBlock.gif       get dot.gifreturn hasMedia; } 
186ExpandedSubBlockEnd.gif       }
 
187InBlock.gif       public IList<ItemInfo> Items 
188ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
189ExpandedSubBlockStart.gifContractedSubBlock.gif       set dot.gif{ items = value; } 
190ExpandedSubBlockStart.gifContractedSubBlock.gif       get dot.gifreturn items; } 
191ExpandedSubBlockEnd.gif       }
 
192ExpandedSubBlockEnd.gif     #endregion
 
193InBlock.gif       
194ContractedSubBlock.gifExpandedSubBlockStart.gif       Private method#region Private method 
195InBlock.gif       
196InBlock.gif       private void WritePrologue() 
197ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
198InBlock.gif       rssWriter.WriteStartDocument(); 
199InBlock.gif       rssWriter.WriteStartElement("rss"); 
200InBlock.gif       rssWriter.WriteAttributeString("version""2.0"); 
201InBlock.gif       rssWriter.WriteAttributeString("xmlns:media", XMLNS_MEDIA); 
202InBlock.gif       rssWriter.WriteAttributeString("xmlns:dc", XMLNS_DC); 
203InBlock.gif       rssWriter.WriteString("\n "); 
204InBlock.gif       // Write in channel block 
205InBlock.gif       rssWriter.WriteStartElement("channel"); 
206InBlock.gif       rssWriter.WriteString("\n "); 
207InBlock.gif       rssWriter.WriteElementString("title", TITLE); 
208InBlock.gif       rssWriter.WriteString("\n "); 
209InBlock.gif       rssWriter.WriteElementString("link", LINK); 
210InBlock.gif       rssWriter.WriteString("\n "); 
211InBlock.gif       rssWriter.WriteElementString("description", DESCRIPTION); 
212InBlock.gif       rssWriter.WriteString("\n "); 
213InBlock.gif       rssWriter.WriteElementString("pubDate", PUB_DATE); 
214InBlock.gif       rssWriter.WriteString("\n "); 
215InBlock.gif       rssWriter.WriteElementString("lastBuildDate", LAST_BUILD_DATE); 
216InBlock.gif       rssWriter.WriteString("\n "); 
217InBlock.gif       rssWriter.WriteElementString("language", LANGUAGE); 
218InBlock.gif       rssWriter.WriteString("\n "); 
219InBlock.gif       rssWriter.WriteElementString("copyright", COPYRIGHT); 
220InBlock.gif       rssWriter.WriteString("\n "); 
221InBlock.gif       rssWriter.WriteElementString("generator", GENERATOR); 
222InBlock.gif       rssWriter.WriteString("\n "); 
223InBlock.gif       // Write in image block 
224InBlock.gif       rssWriter.WriteStartElement("image"); 
225InBlock.gif       rssWriter.WriteString("\n "); 
226InBlock.gif       rssWriter.WriteElementString("url", IMAGE_URL); 
227InBlock.gif       rssWriter.WriteString("\n "); 
228InBlock.gif       rssWriter.WriteElementString("title", IMAGE_TITLE); 
229InBlock.gif       rssWriter.WriteString("\n "); 
230InBlock.gif       rssWriter.WriteElementString("link", IMAGE_LINK); 
231InBlock.gif       rssWriter.WriteString("\n "); 
232InBlock.gif       rssWriter.WriteEndElement(); 
233InBlock.gif       rssWriter.WriteString("\n "); 
234ExpandedSubBlockEnd.gif       }
 
235InBlock.gif       
236ExpandedSubBlockStart.gifContractedSubBlock.gif       /**//**//**//// <summary> 
237InBlock.gif       /// Write in items 
238ExpandedSubBlockEnd.gif       /// </summary> 

239InBlock.gif       private void WriteItem(ItemInfo item) 
240ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
241InBlock.gif       // Write in item block 
242InBlock.gif       rssWriter.WriteStartElement("item"); 
243InBlock.gif       rssWriter.WriteString("\n "); 
244InBlock.gif       rssWriter.WriteElementString("title", item.ItemTitle); 
245InBlock.gif       rssWriter.WriteString("\n "); 
246InBlock.gif       rssWriter.WriteElementString("link", item.ItemLink); 
247InBlock.gif       rssWriter.WriteString("\n "); 
248InBlock.gif       
249InBlock.gif       rssWriter.WriteStartElement("description"); 
250InBlock.gif       rssWriter.WriteString("\n "); 
251InBlock.gif       rssWriter.WriteCData(item.ItemDescription); 
252InBlock.gif       rssWriter.WriteString("\n "); 
253InBlock.gif       rssWriter.WriteEndElement(); 
254InBlock.gif       
255InBlock.gif       rssWriter.WriteString("\n "); 
256InBlock.gif       rssWriter.WriteElementString("pubDate", item.ItemPubDate); 
257InBlock.gif       rssWriter.WriteString("\n "); 
258InBlock.gif       rssWriter.WriteElementString("dc:date.Taken", item.ItemDateTaken); 
259InBlock.gif       rssWriter.WriteString("\n "); 
260InBlock.gif       rssWriter.WriteElementString("author", item.ItemAuthor); 
261InBlock.gif       rssWriter.WriteString("\n "); 
262InBlock.gif       rssWriter.WriteStartElement("guid"); 
263InBlock.gif       rssWriter.WriteAttributeString("isPermaLink""false"); 
264InBlock.gif       rssWriter.WriteString(item.ItemGuid); 
265InBlock.gif       rssWriter.WriteEndElement(); 
266InBlock.gif       
267InBlock.gif       
268InBlock.gif       // Write item media here 
269InBlock.gif       
270ExpandedSubBlockEnd.gif       }
 
271InBlock.gif       
272ExpandedSubBlockStart.gifContractedSubBlock.gif       /**//**//**//// <summary> 
273InBlock.gif       /// Write in item media 
274InBlock.gif       /// </summary> 
275ExpandedSubBlockEnd.gif       /// <param name="item">ItemInfo item</param> 

276InBlock.gif       private void WriteItemMedia(ItemInfo item) 
277ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
278InBlock.gif       // Write in media 
279InBlock.gif       rssWriter.WriteString("\n "); 
280InBlock.gif       rssWriter.WriteStartElement("media:content"); 
281InBlock.gif       rssWriter.WriteAttributeString("url", item.MediaContentUrl); 
282InBlock.gif       rssWriter.WriteAttributeString("type""image/jpeg"); 
283InBlock.gif       rssWriter.WriteEndElement(); 
284InBlock.gif       rssWriter.WriteString("\n "); 
285InBlock.gif       rssWriter.WriteElementString("media:title", item.MediaTitle); 
286InBlock.gif       rssWriter.WriteString("\n "); 
287InBlock.gif       rssWriter.WriteStartElement("media:text"); 
288InBlock.gif       rssWriter.WriteAttributeString("type""html"); 
289InBlock.gif       rssWriter.WriteString(item.MediaDescription); 
290InBlock.gif       rssWriter.WriteEndElement(); 
291InBlock.gif       rssWriter.WriteString("\n "); 
292InBlock.gif       rssWriter.WriteStartElement("media:thumbnail"); 
293InBlock.gif       rssWriter.WriteAttributeString("url", item.MediaThumbUrl); 
294InBlock.gif       rssWriter.WriteAttributeString("height", item.MediaThumbHeight); 
295InBlock.gif       rssWriter.WriteAttributeString("width", item.MediaThumbWidth); 
296InBlock.gif       rssWriter.WriteEndElement(); 
297InBlock.gif       rssWriter.WriteString("\n "); 
298InBlock.gif       rssWriter.WriteStartElement("media:credit"); 
299InBlock.gif       rssWriter.WriteAttributeString("role""photographer"); 
300InBlock.gif       rssWriter.WriteString(item.MediaAuthor); 
301InBlock.gif       rssWriter.WriteEndElement(); 
302InBlock.gif       rssWriter.WriteString("\n "); 
303InBlock.gif       
304ExpandedSubBlockEnd.gif       }
 
305InBlock.gif       
306ExpandedSubBlockStart.gifContractedSubBlock.gif       /**//**//**//// <summary> 
307InBlock.gif       /// Close item element 
308ExpandedSubBlockEnd.gif       /// </summary> 

309InBlock.gif       private void WriteItemEnd() 
310ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
311InBlock.gif       rssWriter.WriteString("\n "); 
312InBlock.gif       rssWriter.WriteEndElement(); 
313InBlock.gif       rssWriter.WriteString("\n "); 
314ExpandedSubBlockEnd.gif       }
 
315InBlock.gif       
316ExpandedSubBlockStart.gifContractedSubBlock.gif       /**//**//**//// <summary> 
317InBlock.gif       /// Close all the elements 
318ExpandedSubBlockEnd.gif       /// </summary> 

319InBlock.gif       private void WriteEnd() 
320ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
321InBlock.gif       rssWriter.WriteEndElement(); 
322InBlock.gif       rssWriter.WriteString("\n"); 
323InBlock.gif       rssWriter.WriteEndElement(); 
324InBlock.gif       rssWriter.WriteEndDocument(); 
325ExpandedSubBlockEnd.gif       }
 
326InBlock.gif       
327ExpandedSubBlockEnd.gif       #endregion
 
328InBlock.gif       
329ExpandedSubBlockStart.gifContractedSubBlock.gif       /**//**//**//// <summary> 
330InBlock.gif       /// Write RSS feed 
331ExpandedSubBlockEnd.gif       /// </summary> 

332InBlock.gif       public void WriteRSS() 
333ExpandedSubBlockStart.gifContractedSubBlock.gif       dot.gif
334InBlock.gif           WritePrologue(); 
335InBlock.gif           foreach (ItemInfo info in items) 
336ExpandedSubBlockStart.gifContractedSubBlock.gif           dot.gif
337InBlock.gif               WriteItem(info); 
338InBlock.gif               if (hasMedia) 
339InBlock.gif               WriteItemMedia(info); 
340InBlock.gif               WriteItemEnd(); 
341ExpandedSubBlockEnd.gif           }
 
342InBlock.gif         WriteEnd(); 
343ExpandedSubBlockEnd.gif       }

344InBlock.gif 
345InBlock.gif
346ExpandedSubBlockEnd.gif     }
  
347ExpandedBlockEnd.gif   }
 
然后使用一个FeedBase.cs类,调用上面的RssBase类中的方法和属性。代码如下
 1 None.gif public   void  GenerateRss()
 2 ExpandedBlockStart.gifContractedBlock.gif     dot.gif {
 3InBlock.gif        IList<MyMedia.Utilities.RssBase.ItemInfo> items = new List<MyMedia.Utilities.RssBase.ItemInfo>();
 4InBlock.gif
 5InBlock.gif        // Populate items. 
 6InBlock.gif        DataTable dt = new DataTable();
 7InBlock.gif        dt.Columns.Add("Title");
 8InBlock.gif        dt.Columns.Add("Description");
 9InBlock.gif        dt.Columns.Add("PubDate");
10InBlock.gif        dt.Columns.Add("Author");
11InBlock.gif
12InBlock.gif        DataRow dr = dt.NewRow();
13InBlock.gif        dr[0= "t1";
14InBlock.gif        dr[1= "t2";
15InBlock.gif        dr[2= "t3";
16InBlock.gif        dr[3= "t4";
17InBlock.gif        dt.Rows.Add(dr);
18InBlock.gif        dt.AcceptChanges();
19InBlock.gif        this.GridView1.DataSource = dt;
20InBlock.gif        GridView1.DataBind();
21InBlock.gif        foreach (DataRow row in dt.Rows)
22ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
23InBlock.gif            MyMedia.Utilities.RssBase.ItemInfo item = new MyMedia.Utilities.RssBase.ItemInfo(row["Title"].ToString(), "link", row["Description"].ToString(), row["PubDate"].ToString(), row["Author"].ToString(), "guid");
24InBlock.gif            items.Add(item);
25ExpandedSubBlockEnd.gif        }

26InBlock.gif
27InBlock.gif        XmlTextWriter xmlWriter = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
28InBlock.gif
29InBlock.gif        MyMedia.Utilities.RssBase rssBase = new MyMedia.Utilities.RssBase(xmlWriter, false, items);
30InBlock.gif        rssBase.WriteRSS();
31InBlock.gif
32InBlock.gif        xmlWriter.Flush();
33InBlock.gif        xmlWriter.Close();
34InBlock.gif
35InBlock.gif        Response.ContentEncoding = Encoding.UTF8;
36InBlock.gif        Response.ContentType = "text/xml";
37InBlock.gif        Response.Cache.SetCacheability(HttpCacheability.Public);
38InBlock.gif
39InBlock.gif        Response.End();
40ExpandedBlockEnd.gif    }

转载于:https://www.cnblogs.com/caviare/archive/2006/12/27/604962.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值