Using the Fluent API to import blog posts from an RSS feed
Here is what I'm trying to do:
using System;using System.Linq;using Telerik.Sitefinity;using System.Xml.Linq;namespace SitefinityWebApp public partial class test : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) // Get the RSS feed from Sitefinity Watch var blogRSS = XDocument.Load("http://feeds.feedburner.com/SitefinityWatch"); // Get the RSS items from the feed var rssItems = from d in blogRSS.Descendants("item") select d; // Get the ID associated with my Sitefinity Watch blog var blogId = (from b in App.WorkWith().Blogs().Get() where b.Title == "Sitefinity Watch" select b).First().Id; // Print the ID, to confirm I got it (this works!) Response.Write(blogId.ToString() + "<br />"); // Loop through each RSS item foreach (var item in rssItems.ToList()) // Print the Title for each blog post (this works!) Response.Write(item.Element("title").Value + "<br />"); // Add the blog post from the RSS feed to my Sitefinity 4.0 blog App.WorkWith() .Blog(blogId) .BlogPost() .CreateNew() .Do(b => b.Title = item.Element("title").Value; b.Content = item.Element("description").Value; ) .SaveChanges(); // No error is thrown, but this does't work Hello Gabe Sumner,
You have to modify your code as shown below
foreach (var item in rssItems.ToList()) // Print the Title for each blog post (this works!) Response.Write(item.Element("title").Value + "<br />"); using (var fluent = App.WorkWith()) var blog = fluent.Blog(blogId) .Get(); blog.BlogPosts.Add(fluent.BlogPost() .CreateNew() .Do(b => b.Title = item.Element("title").Value; b.Content = item.Element("description").Value; b.PublicationDate = DateTime.Now; b.ExpirationDate = DateTime.Now.AddDays(10); ) .Get());