[SOLVED] Update datatype configuration programmati...
# help-with-umbraco
s
I'm trying to update a media picker v3 start node. Does anyone know how to do this? I've got this far: var curDataType = _dataTypeService.GetDataType("SteveTest"); var curConfiguration = (Umbraco.Cms.Core.PropertyEditors.MediaPicker3Configuration)(curDataType.Configuration); curConfiguration.StartNodeId = Udi.Create(Constants.UdiEntityType.Media, Guid.Parse("cf7caaed6477472f9ef157f808f9a15e")); curDataType.Configuration = curConfiguration; This gives me: System.ArgumentException: 'Configurations are kinda non-mutable. Do not reassign the same object. (Parameter 'value')'
a
What happens if you skip the the last line?
s
Nothing changes / is updated
a
But still an exception?
s
No - it is defintely on that assignment it throws an exception
Dave Woestenborghs has solved it for me (via the forum): var curDataType = _dataTypeService.GetDataType("SteveTest"); ((Umbraco.Cms.Core.PropertyEditors.MediaPicker3Configuration)curDataType.Configuration).StartNodeId = Udi.Create(Constants.UdiEntityType.Media, Guid.Parse("cf7caaed6477472f9ef157f808f9a15e"));
a
AFAIK that's almost the same as the three first lines from your first example. I'm assuming you also called the
Save
method in either case?
s
Yes- the issue is I was setting the entire configuration back - DW's way just operates on it rather than cloning it and reassinging the whole configuration. You're right - the next line is obviously a _contentService.Save(xx) I've seen a forum post asking for exactly the solution I was trying to build here - I'll post the full code if I find it as no doubt it will be me googling the same thing in 6 months 🙂
2 Views