---
title: Create a page programmatically
slug: cms-11/dev-docs/creating-a-page-programmatically
docTags: 
createdAt: 2026-07-22T19:45:22.322Z
---

1. Decide where you want your page published in the structure of the website by specifying a `ContentReference` object pointing to the desired parent page, such as the start page, as in the following code:

```csharp
var parent = ContentReference.StartPage;
```

2. Create an empty page with default values, according to the property settings of its page type, by specifying the parent under which to create the page and by specifying the page type:

```csharp
IContentRepository contentRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>();
  PageData myPage = contentRepository.GetDefault<StandardPage>(parent);
```

3. After you create an empty page under the specified parent page programmatically, specify page property values before you publish the page, as shown in the following example:

```javascript
myPage.PageName = "My new page";
```

The code example below shows how to define the user-defined property `MainBody`:

```javascript
myPage.MainBody = "<p>This is produced programmatically.</p>";
```

The following case shows how to assign a content property when a typed model is not known:

```javascript
myPage.Property["MainBody"].Value = "<p>This is produced programmatically.</p>";
```

4. Publish the newly created page by calling the `Save` method of the `DataFactory` class:

```javascript
contentRepository.Save(myPage, EPiServer.DataAccess.SaveAction.Publish);
```

:::hint{type="info"}
**Note**
The method call requires that the current user has the proper permissions to publish a page in this location. This causes a problem if the current user is an anonymous user and you still want the page to be published programmatically. You can use another overload of the `Save` method to permit the publishing, even if the current user does not have the necessary permissions:

```javascript
contentRepository.Save(myPage, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);
```
:::
