private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs args) { //Here I want to get a Umbraco Field value that exists in the Root document/template. }
}
How can I get and read the value for the saved Node(s), and get the Umbraco Field value ? I'm wanting to get the value of the property from the database, not the cache.
When I try to do e.PublishedEntities.First().Properties["isAChannel"].Value I get the error:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'First' and extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could not be found (are you missing a using directive or an assembly reference?)
This is my code by the way
void Document_AfterPublish2(IPublishingStrategy sender, PublishEventArgse) { var Alias = ""; foreach (var entity in e.PublishedEntities) { Alias = entity.ContentType.Name;
}
var isChannel= e.PublishedEntities.First().Properties["isAChannel"].Value;
Get Document by Node Id in ContentService.Published
I have added a application event handler so I can catch when a document is Saved/Published.
public class UmbracoEvent : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Published += ContentServicePublished;
}
private void ContentServicePublished(IPublishingStrategy sender, PublishEventArgs args)
{
//Here I want to get a Umbraco Field value that exists in the Root document/template.
}
}
How can I get and read the value for the saved Node(s), and get the Umbraco Field value ? I'm wanting to get the value of the property from the database, not the cache.
Hi Tommo,
Try:
Thank you. I managed to access the required property field using
args.PublishedEntities.First().Properties["hotelId"].Value
Hi,
When I try to do e.PublishedEntities.First().Properties["isAChannel"].Value I get the error:
'System.Collections.Generic.IEnumerable' does not contain a definition for 'First' and extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could not be found (are you missing a using directive or an assembly reference?)
This is my code by the way
void Document_AfterPublish2(IPublishingStrategy sender, PublishEventArgse)
{
var Alias = "";
foreach (var entity in e.PublishedEntities)
{
Alias = entity.ContentType.Name;
}
var isChannel= e.PublishedEntities.First().Properties["isAChannel"].Value;
}
Am I missing something about his issue?
Thanks
Hi Mario,
How did you subscribe to the Published event? It should be from ContentService: ContentService.Published += Document_AfterPublish2;
In case < IContent> was stripped out by this text editor, try to replace PublishEventArgs e with PublishEventArgs < IContent> e:
private void Document_AfterPublish2(IPublishingStrategy sender, PublishEventArgs< IContent> e) {
}
Hi Bogdan,
It was jus this text editor that stripped the <IContent>. Yes I'm using the Publish event like this:
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ContentService.Published += Document_AfterPublish2;
}
I'm just thinking if I'm missing a reference or something?
Oh yeah, First() is an extension from System.Linq, so add using System.Linq;
Bogdan,
Yes I was missing that reference duh :D
Thank you very much. All is working fine now!
is working on a reply...