Click here to Skip to main content
14,428,429 members
Rate this:
Please Sign up or sign in to vote.
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

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 22: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.
je30ca 28-Sep-14 3:30am
   
i update my question...

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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++;
}
   
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
OriginalGriff 5,198
Richard MacCutchan 1,959
phil.o 1,280
Patrice T 1,267
MadMyche 1,185



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100