Copied to clipboard

Flag this post as spam?

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


  • Nikola 12 posts 132 karma points
    Nov 07, 2018 @ 10:02
    Nikola
    0

    How can I access the file history from the backend

    Hello, I want to get the first publish date and I saw that there is a file history under info: File history under info

    Is there a way to access this information from the backend (inside a cshtml file for example)?

    Thanks in advance

    Nikola

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Nov 07, 2018 @ 14:29
    Dan Diplo
    100

    Umbraco does expose a service called the AuditService that can get some of this data, though I've not used it.

    You can access it like this from a template:

    ApplicationContext.Services.AuditService

    This has a method called GetPagedItemsByEntity() that might do what you want, though it's more designed to get an entire audit history. But you should be able to query it for the first element. Be aware this hits the database a lot, so I wouldn't necessarily use this with a page that is accessed a lot.

    Failing that, you'd have to query the 'umbracoLog' table with SQL directly to get this info. I've written an Audit Log viewer package from Umbraco that does just this and source code is here if this helps - https://github.com/DanDiplo/Umbraco.AuditLogViewer

  • Nikola 12 posts 132 karma points
    Nov 12, 2018 @ 07:25
    Nikola
    0

    Is your Audit Log viewer hiting the database less?

  • Dan Diplo 1554 posts 6205 karma points MVP 5x c-trib
    Nov 12, 2018 @ 13:27
    Dan Diplo
    1

    No, it still hits the database. But it's a back-end tool aimed at Developers, so is only run on demand by people who have access to the Developer area of Umbraco.

    My concern would be if you were running a query that hits the database on every page load - that wouldn't be too efficient (if it's a high volume site). You could probably add some caching etc. to make it perform better, though.

Please Sign in or register to post replies

Write your reply to:

Draft