Set MediaItem on ImageField

允我心安 提交于 2019-12-10 20:24:20

问题


Currently mediaItem.Src is throwing an obsolete warning and states using the MediaItem property instead. The mediaItem.MediaItem has no setter though. Is this warning really just to get people to use something like:

var image = new Sitecore.Data.Items.MediaItem(imageField.MediaItem);
Sitecore.Resources.Media.MediaManager.GetMediaUrl(image);

Is .Src (and related field properties) still the recommended way to actually set the field's value?


回答1:


I believe you'd set the media ID instead of the media item property.




回答2:


I would refer to the Content API Cookbook (PDF link) under section 4.1.7

Some sample code from it:

home.Editing.BeginEdit();
imageField.Clear();
imageField.Src = Sitecore.Resources.Media.MediaManager.GetMediaUrl(sampleMedia);
imageField.MediaID = sampleMedia.ID;
imageField.MediaPath = sampleMedia.MediaPath;
...


来源:https://stackoverflow.com/questions/11399980/set-mediaitem-on-imagefield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!