Skip to content

Instantly share code, notes, and snippets.

@naepalm
Last active Dec 3, 2015
Embed
What would you like to do?
A little razor template snippet that re-saves/republishes all media in Umbraco
@using Umbraco.Core.Models;
@{
var mediaService = ApplicationContext.Current.Services.MediaService;
SaveMedias(mediaService.GetRootMedia().ToList());
}
@functions
{
public void SaveMedias(List<IMedia> medias)
{
var _mediaService = ApplicationContext.Current.Services.MediaService;
if (medias == null || !medias.Any())
return;
foreach (IMedia media in medias)
{
_mediaService.Save(media);
SaveMedias(media.Children().ToList());
Response.Write(media.Name + " saved at:" + media.UpdateDate + "<br />");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment