Benzer Yazılar
Update Asset Description for Sitecore Content Hub
Sample C Sharp code I've written for updating Asset Description for Sitecore Content Hub
Sample C Sharp code I've written for updating Asset Description for Sitecore Content Hub.
You can use it as you like, you may even change and develop your own code.
using System.Globalization;
long assetId = -1;
IEntity thisAsset = null;
string assetTitle = null;
string assetFileName = null;
string assetDescription = null;
string updatedDescription = null;
CultureInfo culture = new CultureInfo("en-US", false);
try
{
MClient.Logger.Info($"Begin script run...");
long? tempId = Context.TargetId;
if(tempId.HasValue)
{
assetId = tempId.Value;
MClient.Logger.Info($"The Asset Id is {assetId}");
thisAsset = await MClient.Entities.GetAsync(assetId);
MClient.Logger.Info($"The Asset Identifier is {thisAsset.Identifier}, and entity definition name is {thisAsset.DefinitionName}
");
assetTitle = thisAsset.GetPropertyValue("Title");
assetFileName = thisAsset.GetPropertyValue("FileName");
updatedDescription = $"The asset title is {assetTitle}, and file name is {assetFileName}.";
MClient.Logger.Info(updatedDescription);
thisAsset.SetPropertyValue("Description", culture, updatedDescription);
await MClient.Entities.SaveAsync(thisAsset);
}
else
{
MClient.Logger.Info($"The TargetId is null, exiting.");
throw new Exception("Null value exception, No TargetId in the Context");
}
}
catch (Exception e)
{
MClient.Logger.Error($"{e.Message}");
}
Sample C Sharp code I've written for updating Asset Description for Sitecore Content Hub