我有一个sitecore Item' CurrentItem
'带有字段" image
".我从后面的代码编辑它如下:
//Get the Image from /sitecore/media library/Images/Test Item imageItem = Sitecore.Context.Database.GetItem("{AEBB3071-3462-405C-9CD3-A2B515B343D1}") //Edit CurrentItem.Editing.BeginEdit(); CurrentItem["image"] = imageItem.ToString(); CurrentItem.Editing.EndEdit();
PS: imageItem
是一张照片/sitecore/media library/Images/Test
我也试过CurrentItem["image"] = imageItem.Paths.Path;
但仍然没有运气.
您需要将该字段作为ImageField
并将MediaID属性设置为MediaItem的ID:
//Get the Image from /sitecore/media library/Images/Test Sitecore.Data.Items.MediaItem imageItem = Sitecore.Context.Database.GetItem("{AEBB3071-3462-405C-9CD3-A2B515B343D1}") //Edit CurrentItem.Editing.BeginEdit(); var imageField = CurrentItem.Fields["image"] as ImageField; imageField.MediaID = imageItem.ID; imageField.MediaPath = imageItem.MediaPath; CurrentItem.Editing.EndEdit();
您还可以查看此博客文章,了解有关6.X版本后的更多说明.