Copied to clipboard

Flag this post as spam?

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


  • Nikola 5 posts 95 karma points
    1 week ago
    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 1385 posts 5201 karma points MVP 2x c-trib
    1 week ago
    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 5 posts 95 karma points
    3 days ago
    Nikola
    0

    Is your Audit Log viewer hiting the database less?

  • Dan Diplo 1385 posts 5201 karma points MVP 2x c-trib
    3 days ago
    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