Good day forum!
I’ve been importing content for years now and have always struggled to find out the right strongly typed model to use for the job.
As a simple example, the Link
object can be imported like below:
Link linkObj = new Link() { Url = "/", Target = "_blank" };
treeNode.SetValue(nameof(StandardPage.Link), JsonSerializer.Serialize(linkObj));
The issue comes with more complex types. Take a property with an editor of Umbraco.MediaPicker3
- how does this work? We can sneak a look at the model builder definition, which gives us MediaWithCrops
. I’ve not had any success with these complex objects, so ended up using a List for this:
List<Dictionary<string, string>>? websiteThumbnail = _umbracoMediaImporter.ConvertPathToUmbracoObject(ogImg);
if (websiteThumbnail != null)
{
var imgJson = JsonConvert.SerializeObject(websiteThumbnail);
treeNode.SetValue(nameof(StandardPage.SeoImage), imgJson);
}
Obviously this is a fairly long-winded process and prone to errors, and although I understand the structure of the objects I’d like a “proper” way to go about this.
I have read the docs and found this; which is great, but doesn’t really give guidance on how to actually find the model that you should use.