Documentation > CMS Template API Library > Asset > CreateNewAsset(String,Asset,Asset,Dictionary[String,String],Boolean)

CreateNewAsset

Creates an asset in the given folder using a given model.

public CrownPeak.CMSAPI.Asset CreateNewAsset(String,Asset,Asset,Dictionary[String,String],Boolean)



Parameters

NameDescriptionType
label

The name of the asset.

System.String
saveLocation

The folder to save this asset.

CrownPeak.CMSAPI.Asset
model

The model for this asset.

CrownPeak.CMSAPI.Asset
contentFields

The content fields for this asset.

Dictionary
createModelChildren

if set to true will also create the model's children if the model is of type Folder.

System.Boolean

Code Example

C#

Sample:

            Asset folderAsset = Asset.Load("/Site/myFolder");
            // Use Asset.LoadDirect() to load the model because models are usually in "Draft".
            Asset modelAsset = Asset.LoadDirect("/System/Models/MyModel");
            // Some properties that will be added to the new assets content when we call CreateNewAsset
            Dictionary<string, string> contentFields = new Dictionary<string, string>  { {"key1", "toy 1"},  {"key2", "toy 2"} };
            //Create the asset.
            Asset newAsset = Asset.CreateNewAsset("newname", folderAsset, modelAsset, contentFields);
            if (!newAsset.IsLoaded)
            Out.WriteLine("Create Failed: " + context.Error);
            

Connect with Crownpeak