Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello, I need help to realize, for an Umbraco 7 website, a custom handler to auto-fill a property on new node creation.
For example...every time I create a new node I immediately must:
I made several attempts but they don't work Can anyone help me? Thank you Adriano
Can you use ContentService Saving for this?
Yeah...I found the solution last week exactly with the contentService.
This is an example code:
using System; using Umbraco.Core; using Umbraco.Core.Events; using Umbraco.Core.Models; using Umbraco.Core.Publishing; using Umbraco.Core.Services; namespace myNameSpace { public class myHandler : ApplicationEventHandler { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { ContentService.Saving += ContentServiceSaving; } private void ContentServiceSaving(IContentService sender, SaveEventArgs<IContent> args) { foreach (var node in args.SavedEntities) { foreach (var property in node.Properties) { if ((property.Alias == "title") && (String.IsNullOrEmpty(property.Value.ToString()))) { property.Value = node.Name; } if ((property.Alias == "date") && (String.IsNullOrEmpty(property.Value.ToString()))) { property.Value = DateTime.Now; } } } } } }
That's all!!!
Glad to help.
Adriano
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Custom handlers
Hello, I need help to realize, for an Umbraco 7 website, a custom handler to auto-fill a property on new node creation.
For example...every time I create a new node I immediately must:
I made several attempts but they don't work Can anyone help me? Thank you Adriano
Can you use ContentService Saving for this?
Yeah...I found the solution last week exactly with the contentService.
This is an example code:
That's all!!!
Glad to help.
Adriano
is working on a reply...