Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Configuration;
- using System.IO;
- using System.Xml;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- /// <summary>
- /// Summary description for rss
- /// </summary>
- public class rss
- {
- public rss()
- {
- //
- // TODO: Add constructor logic here
- //
- }
- public static void Generate(string strRssPath)
- {
- try
- {
- //Fysisk sökväg på servern
- string strXMLPath = strRssPath;
- FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
- XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument();
- //skriv ut <rss version="2.0">
- xtw.WriteStartElement("rss");
- xtw.WriteAttributeString("version", "2.0");
- //skriv ut <channel>
- xtw.WriteStartElement("channel");
- //skriv ut element som tillhör <channel>
- xtw.WriteElementString("title", "Teknikfreak");
- xtw.WriteElementString("link", "http://www.teknikfreak.se/");
- xtw.WriteElementString("description", "Data, mobil, ljudteknik, filmteknik m.m");
- xtw.WriteElementString("language", "sv-SE");
- xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
- NewsCollection newsGetLatestNewsToRSS = bll_tekniknyheter.GetLatestNewsToRSS();
- int i;
- for (i = 0; i < newsGetLatestNewsToRSS.Count; i++)
- {
- string strTitle = newsGetLatestNewsToRSS[i].Headline;
- string strNewsId = newsGetLatestNewsToRSS[i].Id.ToString();
- bool boolRssFeed = newsGetLatestNewsToRSS[i].RssFeed;
- string strDescription;
- if (boolRssFeed)
- {
- strDescription = (newsGetLatestNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
- }
- else
- {
- strDescription = System.Web.HttpUtility.HtmlEncode(newsGetLatestNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
- }
- strDescription = RegExp.UrlBB(strDescription);
- strDescription = RegExp.Bold(strDescription);
- strDescription = RegExp.Italic(strDescription);
- strDescription = RegExp.Ul_list(strDescription);
- strDescription = RegExp.Li_list(strDescription);
- strDescription = RegExp.Underlined(strDescription);
- string strpubDate = newsGetLatestNewsToRSS[i].Date.ToUniversalTime().ToString("r");
- //skriv ut <item> och dess innehåll
- xtw.WriteStartElement("item");
- xtw.WriteElementString("title", strTitle);
- xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId +"/" + TextFormat.NoSpecial(strTitle) +".aspx");
- xtw.WriteElementString("description", strDescription);
- xtw.WriteElementString("pubDate", strpubDate);
- xtw.WriteEndElement();
- }
- //skriv ut </channel>
- xtw.WriteEndElement();
- //skriv ut </rss>
- xtw.WriteEndElement();
- //Stäng xml skrivaren
- xtw.Close();
- }
- catch (Exception ex)
- {
- Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
- }
- }
- public static void Tests()
- {
- try
- {
- //Fysisk sökväg på servern
- string strXMLPath = HttpContext.Current.Server.MapPath("~/Recensioner/rss.xml");
- FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
- XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument();
- //skriv ut <rss version="2.0">
- xtw.WriteStartElement("rss");
- xtw.WriteAttributeString("version", "2.0");
- //skriv ut <channel>
- xtw.WriteStartElement("channel");
- //skriv ut element som tillhör <channel>
- xtw.WriteElementString("title", "Teknikfreak- Recensioner");
- xtw.WriteElementString("link", "http://www.teknikfreak.se/");
- xtw.WriteElementString("description", "Här bevakar du samtliga av våra recensioner");
- xtw.WriteElementString("language", "sv-SE");
- xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
- TestsCollection tGetLatestTestsToRSS = bll_recensioner.GetLatestTestsToRSS();
- int i;
- for (i = 0; i < tGetLatestTestsToRSS.Count; i++)
- {
- string strTitle = tGetLatestTestsToRSS[i].Headline;
- string strTestsId = tGetLatestTestsToRSS[i].Id.ToString();
- string strDescription = HttpContext.Current.Server.HtmlEncode(tGetLatestTestsToRSS[i].Text.Substring(0, 400) + "...").Replace(System.Environment.NewLine, "<br />");
- strDescription = RegExp.Url(strDescription);
- strDescription = RegExp.Bold(strDescription);
- strDescription = RegExp.Italic(strDescription);
- strDescription = RegExp.Ul_list(strDescription);
- strDescription = RegExp.Li_list(strDescription);
- string strpubDate = tGetLatestTestsToRSS[i].Date.ToUniversalTime().ToString("r");
- //skriv ut <item> och dess innehåll
- xtw.WriteStartElement("item");
- xtw.WriteElementString("title", strTitle);
- xtw.WriteElementString("link", "http://www.teknikfreak.se/Recensioner/" + strTestsId + "/" + tGetLatestTestsToRSS[i].Category + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
- xtw.WriteElementString("description", strDescription);
- xtw.WriteElementString("pubDate", strpubDate);
- xtw.WriteEndElement();
- }
- //skriv ut </channel>
- xtw.WriteEndElement();
- //skriv ut </rss>
- xtw.WriteEndElement();
- //Stäng xml skrivaren
- xtw.Close();
- }
- catch (Exception ex)
- {
- Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
- }
- }
- public static void TipsTrix()
- {
- try
- {
- //Fysisk sökväg på servern
- string strXMLPath = HttpContext.Current.Server.MapPath("~/TipsTrix/rss.xml");
- FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
- XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument();
- //skriv ut <rss version="2.0">
- xtw.WriteStartElement("rss");
- xtw.WriteAttributeString("version", "2.0");
- //skriv ut <channel>
- xtw.WriteStartElement("channel");
- //skriv ut element som tillhör <channel>
- xtw.WriteElementString("title", "Teknikfreak- Recensioner");
- xtw.WriteElementString("link", "http://www.teknikfreak.se/");
- xtw.WriteElementString("description", "Här bevakar du samtliga av våra Tips & Trix");
- xtw.WriteElementString("language", "sv-SE");
- xtw.WriteElementString("copyright", "Copyright (c) 2006-2009 Teknikfreak");
- TipsTrixCollection ttGetLatestTTToRSS = bll_tipstrix.GetLatestTipsTrixToRSS();
- int i;
- for (i = 0; i < ttGetLatestTTToRSS.Count; i++)
- {
- string strTitle = ttGetLatestTTToRSS[i].Headline;
- string strTipsTrixId = ttGetLatestTTToRSS[i].Id.ToString();
- string strDescription = HttpContext.Current.Server.HtmlEncode(ttGetLatestTTToRSS[i].Text.Substring(0, 200) + "...").Replace(System.Environment.NewLine, "<br />");
- strDescription = RegExp.Url(strDescription);
- strDescription = RegExp.Bold(strDescription);
- strDescription = RegExp.Italic(strDescription);
- strDescription = RegExp.Ul_list(strDescription);
- strDescription = RegExp.Li_list(strDescription);
- string strpubDate = ttGetLatestTTToRSS[i].Date.ToUniversalTime().ToString("r");
- //skriv ut <item> och dess innehåll
- xtw.WriteStartElement("item");
- xtw.WriteElementString("title", strTitle);
- xtw.WriteElementString("link", "http://www.teknikfreak.se/TipsTrix/" + strTipsTrixId + "/" + ttGetLatestTTToRSS[i].Category + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
- xtw.WriteElementString("description", strDescription);
- xtw.WriteElementString("pubDate", strpubDate);
- xtw.WriteEndElement();
- }
- //skriv ut </channel>
- xtw.WriteEndElement();
- //skriv ut </rss>
- xtw.WriteEndElement();
- //Stäng xml skrivaren
- xtw.Close();
- }
- catch (Exception ex)
- {
- Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
- }
- }
- public static void NewsWordpress()
- {
- try
- {
- //Fysisk sökväg på servern
- string strXMLPath = HttpContext.Current.Server.MapPath("~/Tekniknyheter/wordpress.xml");
- FileStream objFileStream = new FileStream(strXMLPath, FileMode.Create);
- XmlTextWriter xtw = new XmlTextWriter(objFileStream, System.Text.Encoding.GetEncoding("iso-8859-1"));
- xtw.Formatting = Formatting.Indented;
- xtw.WriteStartDocument();
- //skriv ut <rss version="2.0">
- xtw.WriteStartElement("rss");
- xtw.WriteAttributeString("version", "2.0");
- //skriv ut <channel>
- xtw.WriteStartElement("channel");
- //skriv ut element som tillhör <channel>
- xtw.WriteElementString("title", "Teknikfreak- Tekniknyheter");
- xtw.WriteElementString("link", "http://www.teknikfreak.se/");
- xtw.WriteElementString("description", "Här bevakar du samtliga av våra Nyheter");
- xtw.WriteElementString("language", "sv-SE");
- xtw.WriteElementString("copyright", "Copyright (c) 2017 Teknikfreak");
- NewsCollection newsGetNewsToRSS = bll_tekniknyheter.GetNewsToRSS();
- int i;
- for (i = 0; i < newsGetNewsToRSS.Count; i++)
- {
- string strTitle = newsGetNewsToRSS[i].Headline;
- string strNewsId = newsGetNewsToRSS[i].Id.ToString();
- string strDescription = HttpContext.Current.Server.HtmlEncode(newsGetNewsToRSS[i].Text).Replace(System.Environment.NewLine, "<br />");
- string strpubDate = newsGetNewsToRSS[i].Date.ToUniversalTime().ToString("r");
- string strImage = newsGetNewsToRSS[i].Image;
- strDescription = RegExp.UrlBB(strDescription);
- strDescription = RegExp.Bold(strDescription);
- strDescription = RegExp.Italic(strDescription);
- strDescription = RegExp.Ul_list(strDescription);
- strDescription = RegExp.Li_list(strDescription);
- strDescription = RegExp.H2(strDescription);
- //skriv ut <item> och dess innehåll
- xtw.WriteStartElement("item");
- xtw.WriteElementString("title", strTitle);
- xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
- xtw.WriteElementString("description", strDescription);
- xtw.WriteElementString("pubDate", strpubDate);
- xtw.WriteStartElement("image");
- xtw.WriteElementString("url", "http://www.teknikfreak.se/Bilder/Nyhetsbilder/" + strImage);
- xtw.WriteElementString("title", strTitle);
- xtw.WriteElementString("link", "http://www.teknikfreak.se/TeknikNyheter/" + strNewsId + "/" + TextFormat.NoSpecial(strTitle) + ".aspx");
- xtw.WriteEndElement();
- TagsCollection tcGetTagsForNews = bll_tekniknyheter.GetTagsForNews(Convert.ToInt32(strNewsId));
- if (tcGetTagsForNews.Count > 0)
- {
- for (i = 0; i < tcGetTagsForNews.Count; i++)
- {
- xtw.WriteStartElement("category");
- xtw.WriteString(tcGetTagsForNews[i].Tag);
- xtw.WriteEndElement();
- }
- }
- //skriv ut </item>
- xtw.WriteEndElement();
- }
- //skriv ut </channel>
- xtw.WriteEndElement();
- //skriv ut </rss>
- xtw.WriteEndElement();
- //Stäng xml skrivaren
- xtw.Close();
- }
- catch (Exception ex)
- {
- Utilities.SendMail("info@teknikfreak.se", "hejahv@teknikfreak.se", "FELMEDDELANDE på Teknikfreak", ex.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement