public
{
void CreateXML()string strselect = "Your Query here";
DataSet ds = ObjectName.ExecuteQuery(strselect, "Table Name");
try
{
string path = HttpContext.Current.Server.MapPath("rss.xml");
XmlTextWriter writer = new XmlTextWriter(path, Encoding.UTF8);
writer.WriteStartDocument();
writer.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='lead.xsl'");
writer.WriteStartElement("rss");
writer.WriteAttributeString("version", "2.0");
writer.WriteStartElement("channel");
writer.WriteElementString("title", "Your Feed Title");
writer.WriteElementString("link", "http://yoursite.com");
writer.WriteElementString("description", "Your description");
writer.WriteElementString("language", "en-us");
string GMTDate = System.TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now).ToString("r");
writer.WriteElementString("lastBuildDate", "
" + GMTDate);
" + GMTDate);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string strTopic = ds.Tables[0].Rows[i]["Topic"].ToString();
string strArticle = ds.Tables[0].Rows[i]["Article"].ToString();
string strlink = "";
string PostDate = ds.Tables[0].Rows[i]["PostDate"].ToString();
string listid = ds.Tables[0].Rows[i]["Id"].ToString(); ;
strlink = "http://www.yoursite.com/index.aspx?Id=" + listid;
strlink = strlink.Replace("\n", "");
writer.WriteStartElement("item");
writer.WriteElementString("title", strTopic);
writer.WriteElementString("link", strlink);
writer.WriteElementString("description", strArticle);
writer.WriteElementString("guid", strlink);
writer.WriteEndElement();
}
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
catch (Exception e)
{
throw e;
}
}
No comments:
Post a Comment