Publish content programmatically
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
namespace Umbraco.Cms.Web.UI.Custom;
public class PublishContentDemo
{
private readonly IContentService _contentService;
public PublishContentDemo(IContentService contentService) => _contentService = contentService;
public void Publish(Guid key)
{
IContent? content = _contentService.GetById(key)
?? throw new InvalidOperationException($"Could not find content with key: {key}.");
_contentService.SaveAndPublishBranch(content, PublishBranchFilter.Default);
}
}Last updated
Was this helpful?