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?
I believe you'd set the media ID instead of the media item property.
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;
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With