# Updating page content programmatically

**URL:** <https://forum.litium.com/t/updating-page-content-programmatically/149>\
**Category:** Questions\
**Created:** [July 5, 2018, 2:46am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149 "2018-07-05T02:46:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zsrdos](https://avatars.discourse-cdn.com/v4/letter/z/74df32/32.png) [@Zsrdos](https://forum.litium.com/u/Zsrdos)\
**Post date:** [July 5, 2018, 2:46am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/1 "2018-07-05T02:46:46Z")

</div>

I’m just getting started with Litium and trying to do some basic tasks to get my head around the system, but I’m having a hard time understanding the documentation.

Basically, I am trying to create a “Regular page” (Article) and populate the fields: “Introduction” and Text1 with text.

I had no problem creating the page or listing the fields/properties but I can’t for the life of me figure out how to set/update the values. Hera are my play code:

```
        string outout = "PageTypes:\n";
    foreach(PageType type in pageTypes)
    {
        outout += type.Name +"\n";

        if(type.Name == "Article")
        {
            
            Page currentPage = pcc.CreatePage(type, type.DefaultTemplate, "TestCreate", true, securityToken);

            //I read someware that i should do it using, PageCarrier but how?
            var pc = currentPage.GetAsCarrier(false, true, true);
            currentPage.UpdateFromCarrier(pc,securityToken);

            var props = currentPage.Content;

            outout = "Property:\n";
            // Or can i update the fields here when loopign over the props?
            foreach (Property prop in props)
            {

                outout += prop.Name + "\n";

            }
        }
    }

```

Litium version: 6.2

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [July 5, 2018, 5:11am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/2 "2018-07-05T05:11:39Z")

</div>

You need to cast the `Property` into the typed property, example `StringShortProperty` and there you have get/set methods for the values. All the different property types exists in the `Litium.Foundation.Modules.CMS.Content` namespace.

Example

```auto
foreach (Property prop in props)
{
    outout += prop.Name + "\n";
    if (prop is StringShortProperty stringShortProperty)
    {
        output += stringShortProperty.GetValue() + "\n";
        stringShortProperty.SetValue("my new value", SecurityToken.CurrentSecurityToken);
        output += stringShortProperty.GetValue() + "\n";
    }
}

```

---

<div class="post-metadata">

**Author:** ![Zsrdos](https://avatars.discourse-cdn.com/v4/letter/z/74df32/32.png) [@Zsrdos](https://forum.litium.com/u/Zsrdos)\
**Post date:** [July 5, 2018, 5:53am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/3 "2018-07-05T05:53:39Z")

</div>

Fantastic, thanks! anything I need to know about PageCarrier? I remember reading that that was the “New way” of updating. Can you tell me something about the logic there? What are a Carrier and how is it used in regards to updating?

---

<div class="post-metadata">

**Author:** ![marten](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/marten/32/11_2.png) [@marten](https://forum.litium.com/u/marten)\
**Post date:** [July 5, 2018, 8:50am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/4 "2018-07-05T08:50:40Z")

</div>

Use `UpdateFromCarrier` when you need to update multiple values of a page at the same time.

The carrier is used to contain the data of a page object, same as OrderCarrier for an order for example.

---

<div class="post-metadata">

**Author:** ![Zsrdos](https://avatars.discourse-cdn.com/v4/letter/z/74df32/32.png) [@Zsrdos](https://forum.litium.com/u/Zsrdos)\
**Post date:** [July 5, 2018, 8:58am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/5 "2018-07-05T08:58:00Z")

</div>

So, I use the Carrier the same way? Like: stringShortProperty.SetValue(“New Value”).  
But then i need to pass it via UpdateFormCarrier(carrier) to update the values? or are the update logic different?

And without a Carrier the database is updated on every SetEvent call?

---

<div class="post-metadata">

**Author:** ![marten](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/marten/32/11_2.png) [@marten](https://forum.litium.com/u/marten)\
**Post date:** [July 5, 2018, 9:07am UTC](https://forum.litium.com/t/updating-page-content-programmatically/149/6 "2018-07-05T09:07:21Z")

</div>

Search for PageCarrier in `\src\Litium.Accelerator\Deployments\CmsStructurePackage.cs` to see usage examples.

And yes on db being called on every Set() call otherwise, this pattern is no longer used in the new API which is currently avaliable for PIM, Media and Customers.
