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
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.
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:
Is there a way to access this information from the backend (inside a cshtml file for example)?
Thanks in advance
Nikola
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
Is your Audit Log viewer hiting the database less?
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.
is working on a reply...