Share and Enjoy !


During a recent migration, we migrated a customer’s blog post content to SharePoint Online from an older system.  The customer wanted to promote blog posts as News Articles so they would be displayed in the News Webparts on the Home Page of the site. Here is the story of how we accomplished the goals of migrated news article pages with the correct publish date.

The Problem

When we ran page.PromoteAsNewsArticle() the Publish Date was being set to the date that the page was created and uploaded into SharePoint Online rather than the original Publish Date from the older system.

Even though the page’s Modified and Created dates reflected the original Modified and Created Dates from the source system, the Published date for these News Articles was the actual migration date.  In addition, when the page was promoted as a news article, the page showed up in the “Latest Activity” for the site and the News web part displayed the blog posts in the order of most recently uploaded to SPO, rather than displaying the most recently published blog post/news articles.  Having so much recent “activity” in the site made it difficult for new users to quickly find the new News Articles in the site.

The Solution

We found a way to set the FirstPublishedDate during page creation so we could control the value of this datetime field, which gets automatically populated with the current datetime when the page is first “promoted as a news article.”

We called the PromoteAsNewsArticle method and then saved the page by calling the Save method for the page.  Then we ran a special method to set the FirstPublishedDate on the page list item in the Site Pages Library before we finally called the Publish method for this new page.  The order of operation was important to be able to override the FirstPublishedDate value.

The Order:

  1. page.PromoteAsNewsArticle();
  2. page.Save(pageName);
  3. UpdateFirstPublishDate(context, page, actualPublishDate, pageName);
  4. page.Publish();

The Code for Promoting Migrated News Article Pages with the Original Publish Date

Below is the actual method for setting “FirstPublishedDate” to a specific DateTime value and allows the original publish date to be maintained for this new page as it migrates over from an older system.

         private void UpdateFirstPublishDate(ClientContext context, ClientSidePage page, DateTime actualPublishedDate, string pageName)
                context.Load(page.PageListItem, p => p["LayoutWebpartsContent"]);
                page.PageListItem["FirstPublishedDate"] = actualPublishedDate;
            catch (Exception ex)
                log.ErrorFormat("Unable to set FirstPublishedDate for page '{0}'.  There was an exception thrown.  {1}", pageName, ex.Message);



Hopefully, this is the answer you were seeking out on how to get the correct publish date on migrated news article pages. If you are going through a migration of yourself and need more useful tips, check out our category of Microsoft 365 Migration blogs.

Share and Enjoy !

Related Content: