Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Below is an example of how it looks:

4.1 How to retrieve metadata from an item placed in the silo bucket

In order to retrieve the metadata for the silo item,  call the following pipeline: DFS.GetAssetMetadata
The GetAssetMetadataArgs takes AssetItemId which is of type Sitecore.Data.ID and ContextLanguage which is of type Sitecore.Globalization.Language.

...

Code Block
languagec#
linenumberstrue
var renderArgs = new GetAssetMetadataArgs { AssetItemId = item.ID, ContextLanguage = Sitecore.Context.Language };
CorePipeline.Run(PipelineNames.GetAssetMetadata, renderArgs);
if (renderArgs.AssetMetadata == null)
{
	return;
}
var name = renderArgs.AssetMetadata.Name;

4.2 How to retrieve metadata for the field type Asset

Code Block
languagec#
linenumberstrue
AssetField assetField = Sitecore.Context.Item.Fields["Asset"]; 
var name = assetField.AssetMetadata.Name; 
Code Block
languagec#
linenumberstrue
AssetlinkField assetLinkField = Sitecore.Context.Item.Fields["AssetLink"]; 
var name = assetLinkField.AssetMetadata.Name; 

4.4 How to retrieve metadata for the field type AssetList

Code Block
languagec#
linenumberstrue
AssetlistField assetList = Sitecore.Context.Item.Fields["AssetList"];
if (assetList != null)
{
	foreach (var asset in assetList.Assets)
		{
		// To request the rendering html for the asset you call the
		// RenderAsset method. It returns an RenderFieldResult object
		var renderResultItem = asset.RenderAsset(); 
		var title = asset.AssetMetadata.Name;
		var id = asset.AssetMetadata.AssetId;
		var assetTypeId = asset.AssetMetadata.AssetTypeId;
		var assetTypeName = asset.AssetMetadata.AssetTypeName; 


		// Get dynamic metadata
		var someDynamicMetadata = asset.AssetMetadata["50343"];
	}
}

4.5 Update asset metadata not supported from code

Updating an items metadata is not supported from code. Use the editor in the DAM Explorer or Asset browser.