Skip to content

Instantly share code, notes, and snippets.

@naepalm
Last active December 3, 2015 19:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save naepalm/902669ba49f3db5eb5ba to your computer and use it in GitHub Desktop.
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