Documentation > CMS Template API Library > Asset > LoadDirect(Int32,Boolean)
LoadDirect
Load an asset with the given asset id, if it exists, regardless of the state or context. Use IsLoaded to see if loading was successful. Don't use this if you expect the asset may be branch. It will load assets, that may not be available on the server where you are publishing.
public CrownPeak.CMSAPI.Asset LoadDirect(Int32,Boolean)
Returns
An asset. IsLoaded will be false if none was found.
Parameters
Name | Description | Type |
---|---|---|
assetId | The id for the asset that you want to return | System.Int32 |
loadDeleted | Optional: Load the asset, even if it has been recently deleted (not yet purged). Defaults to false. | System.Boolean |
Code Example
C#
Sample:
// Use Asset.LoadDirect() to load the model because models are usually in "Draft" and you might be // publishing to "Stage" or "Live", so Load() will not find it. int modelId = 1234; Asset modelAsset = Asset.LoadDirect(modelId); Dictionary<string, string> contentFields = new Dictionary<string, string> { {"key1", "toy 1"}, {"key2", "toy 2"} }; //Create the asset. Asset newAsset = Asset.CreateNewAsset("newname", Asset.Load("/Site/Folder"), modelAsset, contentFields); if (!newAsset.IsLoaded) { Out.WriteLine("Create Failed: " + context.Error);