Retrieve all child assets from a folder in Crownpeak.

Filter assets from a Folder based on Template ID and Workflow Status in Crownpeak

December 29, 2021

In this article, we will cover how to retrieve all child assets from a folder in Crownpeak.

We will also cover how to filter the Assets based on Template ID and Workflow Status and also by adding custom filter logic

To filter the Assets, we will use the FilterParams Class and Linq queries.

Template Input.aspx / Ouput.aspx

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

Asset siteFolder = Asset.Load("/Root Folder/Sites/SiteName/");
if (siteFolder.IsLoaded)
{
    FilterParams assetParams = new FilterParams();
 
    // Add the Workflow here to Exclude from the listing 
    assetParams.ExcludeFilterStatus = Util.MakeList("Archived""Retired""Draft");
 
    // Add the Template Id here to Find Assets which are created using it. 
    assetParams.Add(AssetPropertyNames.TemplateId, Comparison.Equals, 12345);
 
    var all_Assets = siteFolder.GetFilterList(assetParams);
 
    // Add your custom logic to filter with specific conditions.
    all_Assets = all_Assets.Where(w => w.Label.Contains("LabelName")).ToList();
 
    foreach (Asset curAsset in all_Assets)
    {
        // Your Logic to retrieve the Data from each filtered asset
 
        int AssetID = curAsset.Id;
        foreach (PanelEntry pn in curAsset.GetPanels("panel_name"))
        {
            string fname = pn["FirstName"];
        }
    }
}

Post Comments(0)

Leave a reply

Will not be displayed in comment box .

Loading...