RSS檔案輸出(ASP.NET C#版)

iDotNetSpace發表於2009-10-12

StringBuilder sb = new StringBuilder();

            sb.Append("");

            sb.Append(System.Environment.NewLine);

            sb.Append("");

            sb.Append(System.Environment.NewLine);

            sb.Append("  ");

            sb.Append(System.Environment.NewLine);

            sb.Append("    " + title + "");

            sb.Append(System.Environment.NewLine);

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

            sb.Append(System.Environment.NewLine);

            sb.Append("    " + title + "");

            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("    ");

                sb.Append(System.Environment.NewLine);

                sb.Append("      +ae.ArticleTitle+<span style="COLOR: #a31515">"]]></span>");

                sb.Append(System.Environment.NewLine);

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

                sb.Append(System.Environment.NewLine);

                sb.Append("      +ae.Description+"]]>");

                sb.Append(System.Environment.NewLine);

                sb.Append("      "+ae.ArticleAuthor+"");

                sb.Append(System.Environment.NewLine);

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

                sb.Append(System.Environment.NewLine);

                sb.Append("      " + ae.CommentCount.ToString() + "");

                sb.Append(System.Environment.NewLine);

                sb.Append("    ");

                sb.Append(System.Environment.NewLine);

            }

            sb.Append("  ");

            sb.Append(System.Environment.NewLine);

            sb.Append("");

            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的朋友也可以用此方法來嘗試一下!具體程式碼我就不貼出來了!

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-616332/,如需轉載,請註明出處,否則將追究法律責任。

相關文章