+1-888-365-2779
Try Now
More in this section

Forums / Set-up & Installation / Import News content into Sitefinity database

Import News content into Sitefinity database

3 posts, 1 answered
  1. promedia
    promedia avatar
    4 posts
    Registered:
    16 Aug 2004
    12 Nov 2009
    Link to this post
    Hello,

    We're in the middle of moving our existing ASP.NET web site to Sitefinity. We're trying to import our existing News content directly into the Sitefinity database. Our news content is stored in SQL Server 2008 database using a very simple table structure.

    We can see that  /News data is stored in Sitefinity in two tables: sf_CmsContentBase and sf_CmsTextContent

    Is there a tutorial or walkthrough showing how this can be done? We need to move the existing content into Sitefinity so that our existing content will appear in the Sitefinity News sections.

    Thanks!

    Truman

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2009
    Link to this post
    Hi promedia,

    I suggest that you should use the news API to migrate the old news items. It will be easy and this will ensure that there will not be further problems. We use Nolics queries and Sitefinity's API to insert, update, delete content items. There are many internal dependencies between the tables and we do not suggest working directly with the database.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Answered
  3. promedia
    promedia avatar
    4 posts
    Registered:
    16 Aug 2004
    20 Nov 2009
    Link to this post
    1 /* Here is the code we used to connect to our legacy database, loop through each record in
    * the News table, then create a Sitefinity News item for each record. */  
       
    2         // Create a DataContext for legacy database 
    3         Legacy_DataContext dc = new Legacy_DataContext(); 
    4  
    5         // simple LINQ query to get news items from legacy database 
    6         var newsQuery = from newsbrief in dc.News_Briefs 
    7                         select newsbrief; 
    8  
    9         // Create a News item in Sitefinity for each news item in legacy database 
    10         foreach (var nb in newsQuery) 
    11         { 
    12             NewsManager newsBriefs = new NewsManager("News"); 
    13             IContent newsContent = newsBriefs.Content.CreateContent("text/html"); 
    14  
    15             newsContent.Content = nb.Body; 
    16             newsContent.Status = Telerik.Cms.Engine.ContentStatus.Published; 
    17  
    18             // Assign MetaData values from legacy database 
    19             newsContent.SetMetaData("Title", nb.Title); 
    20  
    21             newsContent.SetMetaData("Author""Editorial Staff"); 
    22  
    23             newsContent.SetMetaData("Summary", nb.Teaser); 
    24             newsContent.SetMetaData("Source""Original"); 
    25  
    26             DateTime dt = DateTime.Parse(nb.PostDate.ToString()); 
    27             DateTime edt = dt.AddMonths(6); 
    28  
    29             newsContent.SetMetaData("Publication_Date", dt); 
    30             newsContent.SetMetaData("Expiration_Date", edt); 
    31  
    32             newsBriefs.Content.SaveContent(newsContent); 
    33         } 
Register for webinar
3 posts, 1 answered