In the example below, a new page is programmatically created using the content service. It is assumed that there are two document types, namely Catalogue and Product. In this case, a new Product is added underneath the Catalogue page. Add the below code in the Catalogue template.
For information on how to retrieve multilingual languages, see the Retrieving languages article.
The ContentService acts as a "gateway" to Umbraco data for operations which are related to Content.
Browse the v13 API documentation for ContentService.
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
All samples in this document will require references to the following dll:
Umbraco.Core.dll
All samples in this document will require the following using statements:
For Razor views:
If you wish to use the content service in a class, you need to use Dependency Injection (DI) in your constructor:
In Razor views, you can access the content service through the @inject
directive: