Create Assets Dynamically from output.aspx in Crownpeak

Create and Route Assets Dynamically from output.aspx in Crownpeak

December 29, 2021

In this article, we will cover how to create assets Dynamically from output.aspx in Crownpeak.

We will also cover how to route assets Dynamically from output.aspx in Crownpeak.

To Create the Asset Dynamically, we will need a model (asset to copy) and a Destination Folder where an asset will get created.

Template Ouput.aspx

Add the below-mentioned code to your Template in Output.aspx based on your requirement.

// Model Asset will use to create an asset with the same template id and default content.
Asset model = Asset.LoadDirect("/SiteRoot/Models/Model Asset");
 
// A folder where the new assets will get created dynamically.
Asset DestinationFolder = Asset.Load("/SiteRoot/Destination/");
 
if (DestinationFolder != null && DestinationFolder.IsLoaded)
{
    // Check the asset with the same name already exists in the folder or not.
    Asset Asset_Exists = Asset.LoadDirect(DestinationFolder.AssetPath + "/NewPage");
    if (Asset_Exists == null || Asset_Exists.IsLoaded == false)
    {
        Asset newAsset = Asset.CreateNewAsset("NewPage", DestinationFolder, model, null);
 
        if (newAsset != null && newAsset.IsLoaded)
        {
            // Route the asset to Workflow as per requirement.
            newAsset.Route(Status.Load("LIVE"));
        }
    }
}

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...