Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Tim C 155 posts 512 karma points
    Aug 25, 2016 @ 08:19
    Tim C

    Updating documents via razor code?

    From time to time, with any CMS we come across the need to mass update a set of documents in some way - something needs changing that we hadn't planned for. For example a mass replace of the values in a specific property on a number of pages.

    I have looked at the SQL tables in Umbraco and could probably do it via Transact-SQL but I know this wouldn't update the XML cache in server memory, so would presumably need to restart the application which is not ideal.

    Can it be done from Razor code on a page, or some C# code in App_code?

  • David Peck 589 posts 1557 karma points c-trib
    Aug 25, 2016 @ 11:01
    David Peck

    A few idea:

    1. Migrations
    2. Just calling a controller
    3. LinqPad

    For all of the above you'll then need to use the ContentService, which is a back office API, to call, edit and save your changes.

    Don't use Razor though. That is for use in the views and for the purpose of rendering HTML.

  • Tim C 155 posts 512 karma points
    Aug 25, 2016 @ 11:04
    Tim C

    Thanks, David

Please Sign in or register to post replies

Write your reply to: