欢迎大家来我的Bolg作客!在这里我们将为您提供及时全面的IT信息……

RSS文件输出(ASP.NET C#版)

StringBuilder sb = new StringBuilder();

            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><?xml-stylesheet type=\"text/xsl\" href=\"/Styles/WebBarRss.xslt\"?>");

            sb.Append(System.Environment.NewLine);

            sb.Append("<rss version=\"2.0\">");

            sb.Append(System.Environment.NewLine);

            sb.Append("  <channel>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <title>" + title + "</title>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <link>http://www.###.com</link>");

            sb.Append(System.Environment.NewLine);

            sb.Append("    <description>" + title + "</description>");

            sb.Append(System.Environment.NewLine);

            WebBar.BLL.BArticle bArticle = new WebBar.BLL.BArticle();

            IList<ArticleEntity> ArticleEntitys = bArticle.List(int.Parse(ddlRssCount.SelectedValue.ToString()), int.Parse(ddlChannelID.SelectedValue.ToString()));

            foreach (ArticleEntity ae in ArticleEntitys)

            {

                sb.Append("    <item>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <title><![CDATA["+ae.ArticleTitle+"]]></title>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <link>http://www.###.com/Article/" + ae.ArticleID.ToString() + ".aspx</link>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <description><![CDATA["+ae.Description+"]]></description>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <author>"+ae.ArticleAuthor+"</author>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <pubDate>"+ae.ArticleCreateTime.ToString("yyyy-MM-dd HH:mm")+"</pubDate>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      <comments>" + ae.CommentCount.ToString() + "</comments>");

                sb.Append(System.Environment.NewLine);

                sb.Append("    </item>");

                sb.Append(System.Environment.NewLine);

            }

            sb.Append("  </channel>");

            sb.Append(System.Environment.NewLine);

            sb.Append("</rss>");

            try

            {

                using (FileStream fs = new FileStream(Server.MapPath(xmlFileName), FileMode.Create, FileAccess.Write, FileShare.Write))

                {

                    using (StreamWriter streamwriter = new StreamWriter(fs, Response.ContentEncoding))

                    {

                        streamwriter.Write(sb);

                        Common.JsUtility.Alert("成功生成RSS聚合内容");

                    }

                }

            }

当然:使用JSP,PHP和ASP的朋友也可以用此方法来尝试一下!具体代码我就不贴出来了!

posted @ 2009-10-12 13:56  Cyrus Dai  阅读(401)  评论(1编辑  收藏  举报
Copyright ? 戴超 2008-10-30---9595-95-95