Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have a url rss "http://www.aparat.com/rss/mesbahsoft" that insert items into my database

this rss have not date and id and i want get date of rss and if item was new add to database.
In your opinion, what should I do?

get title and summery and insert into database(my database is a list in sharepoint)

//"http://www.aparat.com/rss/mesbahsoft"
           string url = textBox1.Text;
       XmlReader reader = XmlReader.Create(url);
       SyndicationFeed feed = SyndicationFeed.Load(reader);
       reader.Close();
       foreach (SyndicationItem item in feed.Items)
       {
           String subject = item.Title.Text;
           String summary = item.Summary.Text;

           string siteUrl = "http://server/mypersonal/ref";

           // ClientContext clientContext = new ClientContext(siteUrl);

           using (ClientContext context = new ClientContext(siteUrl))
           {
               context.Credentials = new NetworkCredential(Properties.Settings.Default.Username, "09196654718aA", "mesbahsoft.local");
               List oList = context.Web.Lists.GetByTitle("RssReader");
               // context.ExecuteQuery();
               //SP.List oList = context.Web.Lists.GetByTitle("listtest");

               ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
               ListItem oListItem = oList.AddItem(itemCreateInfo);
               oListItem["Title"] = subject;
               oListItem["Description"] = summary;

               oListItem.Update();


               try
               {

               }
               catch (Exception)
               {
                   //eventLog1.Write
                   throw;
               }
               context.ExecuteQuery();
           }


       }
       MessageBox.Show("success");

       }




i find bottom code for parse content but i dont know how use this

XML
HtmlWeb hw = new HtmlWeb();

           HtmlAgilityPack.HtmlDocument doc = hw.Load(@"http://www.aparat.com/rss/mesbahsoft");
           StringBuilder sb = new StringBuilder();

           List<string> lstHref = new List<string>();

           foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//body").Distinct())
           {
               string curHref = link.Attributes["body"].Value;

               if (!lstHref.Contains(curHref))
                   lstHref.Add(curHref);

           }
           foreach (string str in lstHref)
           {
               sb.Append(str + "<br />");
           }
           textBox1.Text=
           sb.ToString();
Posted
Updated 27-Sep-14 21:30pm
v2
Comments
BillWoodruff 28-Sep-14 2:34am    
Looking at the content of the link you provided, it appears the information is divided into sections each of which has date-time identification. Please clarify what is not present that you want.
je30ca 28-Sep-14 3:05am    
i need date for that Detect is this a new item?
but becouse have not tag pubdate i dont know how get date of in dives...
i get title and summery and insert into my database but date....
BillWoodruff 28-Sep-14 3:11am    
Why can't you parse the content of the page and read the date-time information ?
je30ca 28-Sep-14 3:16am    
i search in google and find HtmlAgilitiPackage but i dont know how use this :(
BillWoodruff 28-Sep-14 3:21am    
To make progress with your question, imho you really need to show us the code you are using now that does whatever you are doing with the RSS you have just read.

1 solution

Each item in that RSS Feed contains a 'PublishDate field which contains a value of Type 'DateTimeOffset.'DateTimeOffset was added to .NET beginning with version 3.5; see: [^].

Here's an example of parsing the 'PublishDate field:
 //"http://www.aparat.com/rss/mesbahsoft"
string url = @"http://www.aparat.com/rss/mesbahsoft";
XmlReader reader = XmlReader.Create(url);
SyndicationFeed feed = SyndicationFeed.Load(reader);
reader.Close();

int count = 1;

foreach (SyndicationItem item in feed.Items)
{
    DateTimeOffset publishDate = item.PublishDate;
    String subject = item.Title.Text;
    String summary = item.Summary.Text;


    Console.WriteLine
    (
        "Item# {0} Title: {1}\nSummary: {2}\nPublish Date-Time: {3} {4} UTC Offset: {5}\n\n",
        count.ToString(),
        subject,
        "summary omitted for testing",
        publishDate.Date.ToShortDateString(),
        publishDate.DateTime.ToShortTimeString(),
        publishDate.Offset.ToString()
    );

    count++;
}
 
Share this answer
 
Comments
je30ca 28-Sep-14 5:13am    
Thanks! it works for me... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900