Last active
December 3, 2015 19:38
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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