Adding new properties to media type when there are existing media items
If i add a new property to a media type (in this case, Image) it doesn't become available to use in code until i've resaved the media item (clicked on save on the image in the CMS).
When there are more than a few images this obviously becomes very tedious. Is there a way to re-save all images so i don't have to do this? This feels like a bug...?
Its a bit hacky but to resave all media items, I've previously created a temporary template which has the following code. It finds all root media items and recursively finds each child, saving each one along the way.
@using umbraco.cms.businesslogic.media
@{
SaveMedias(Media.GetRootMedias());
}
@functions
{
public void SaveMedias(Media[] medias)
{
if (medias == null || !medias.Any())
return;
foreach (var media in medias)
{
Response.Write("Saving " + media.Text + "/n");
media.Save();
SaveMedias(media.Children);
}
}
}
Adding new properties to media type when there are existing media items
If i add a new property to a media type (in this case, Image) it doesn't become available to use in code until i've resaved the media item (clicked on save on the image in the CMS).
When there are more than a few images this obviously becomes very tedious. Is there a way to re-save all images so i don't have to do this? This feels like a bug...?
Hi Paul,
Its a bit hacky but to resave all media items, I've previously created a temporary template which has the following code. It finds all root media items and recursively finds each child, saving each one along the way.
Thanks, Dan.
Thats brilliant thanks! So obvious as well, kicking myself i didn't i think of it!!
is working on a reply...