Documentation > CMS Template API Library > Asset > LoadDirect(String)

LoadDirect

Load an asset with the given asset path, if it exists, regardless of the state or context. If there are two or more assets with the same path, the asset with the highest id number (most-recently created) is returned. Use IsLoaded to see if loading was successful. Don't use this if you expect the asset to have branches. It will load assets, that may not be available on the server where you are publishing.

public CrownPeak.CMSAPI.Asset LoadDirect(String)


Returns

An asset. IsLoaded will be false if none was found.

Parameters

NameDescriptionType
path The path to an asset. Like "/Site/MyFolder/MyAsset" or "". An empty string will return an unloaded asset. Use "/" to load the root. System.String

Code Example

C#

Sample:
// Use Asset.LoadDirect() to load the model because models are usually in "Draft".
Asset modelAsset = Asset.LoadDirect("/System/Models/MyModel");

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);
}

Connect with Crownpeak