2013-07-06 2 views
0

RSS 생성기 파일에서 만든 RSS 피드 정적 파일 항목에 pubDate의 형식을 지정할 수 없습니다. RSS 피드의 헤더에서 제대로 생성 할 수 있지만 String.Format을 제대로 작동시키지 못합니다. 문자열을 둘러싸 기 위해 {}를 사용하면 {} 대괄호를 사용하지 않으면 문자열을 계속 출력합니다. 그러면 오류가 발생합니다.ASP .NET RSS 피드 작성자의 PubDate 서식이 올바르지 않습니다.

String.Format("{0:r}", r["pubDate"]) 

r["pubDate"].ToString() 

교체

public void WriteToFile() 
{ 

string strDate = null; 

strDate = "ddd, dd MMM yyyy HH:mm:ss"; 

File.Delete(Server.MapPath(".") + "\\" + "rss.xml"); 

StreamWriter StrWer = default(StreamWriter); 
try 
{ 
    StrWer = new StreamWriter(Server.MapPath(".") + "\\" + "rss.xml", true); 

    StrWer.WriteLine("<rss version='2.0' xmlns:content = 'http://purl.org/rss/1.0/modules/content/'>"); 
    StrWer.WriteLine(" <channel>"); 
    StrWer.WriteLine(" <title>" + Master.Banner() + " RSS Feed</title>"); 
    StrWer.WriteLine(" <link>" + Master.SiteSearch() + "</link>"); 
    StrWer.WriteLine(" <description>This contains the news of the " + Master.H1first() + " </description>"); 
    StrWer.WriteLine(" <language>en-us</language>"); 
    StrWer.WriteLine(" <image>"); 
    StrWer.WriteLine("   <url>" + Master.SiteSearch() + "images/site/paclogo.png</url>"); 
    StrWer.WriteLine("   <title>" + Master.Banner() + " Logo</title>"); 
    StrWer.WriteLine("   <link>" + Master.SiteSearch() + "</link>"); 
    StrWer.WriteLine(" </image>"); 

    DateTime time = DateTime.Now;    // Use current time 

    StrWer.WriteLine(" <lastBuildDate>" + time.ToString(strDate) + " EST</lastBuildDate>"); 

       SqlCeConnection conn = null; 
       conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["XMLDataSourceReplacement"].ToString()); 
       string sql = "select * from rsssource order by pubDate desc"; 
         SqlCeCommand cmdGetOldMasterId = new SqlCeCommand(sql, conn); 
         SqlCeDataAdapter da = new SqlCeDataAdapter(cmdGetOldMasterId); 
         DataTable dt = new DataTable(); 
         da.Fill(dt); 

         foreach(DataRow r in dt.Rows) 
         { 
          StrWer.WriteLine("  <item>"); 
          StrWer.WriteLine("   <title>" + r["title"].ToString() + "</title>"); 
          StrWer.WriteLine("   <link>" + r["link"].ToString() + "</link>"); 
          StrWer.WriteLine("   <description>" + r["description"].ToString() + "</description>"); 

          //"ddd, dd MMM yyyy HH:mm:ss" 
          string strdate = r["pubDate"].ToString(); 
          string strFormatted = String.Format("{ddd, dd MMM yyyy HH:mm:ss zzz}", strdate); 
          //string strFormatted = String.Format("ddd, dd MMM yyyy HH:mm:ss zzz", strdate); 

          StrWer.WriteLine("   test: " + strFormatted); 
          StrWer.WriteLine("   <pubDate>" + r["pubDate"].ToString() + "</pubDate>"); 
          StrWer.WriteLine("  </item>"); 
         } 

    StrWer.WriteLine(" </channel>"); 
    StrWer.WriteLine("</rss>"); 

    StrWer.Close(); 

    this.lblStatus.Text = "The rss.xml file update succeeded."; 
} 
catch (Exception ex) 
{ 
     this.lblStatus.Text = "The rss.xml file update failed. (" + ex.Message + ")"; 
} 

} 

답변