Previous to our upgrade to 7.6.5, we could do the following with the old multinode treepicker using the content service:
if (ApplicationContext.IsReady) {
var contentService = ApplicationContext.Current.Services.ContentService;
var pageResults = contentService.GetChildren(1220);
if (pageResults != null && pageResults.Any()) {
foreach (var pageItem in pageResults) {
string pageName = pageItem.Name.ToLower().Trim();
if (pageName.StartsWith("thing")) {
pageItem.SetValue("Brand", 2495);
} else {
pageItem.SetValue("Brand", "2276,2495");
}
contentService.SaveAndPublishWithStatus(pageItem);
}
}
}
With the new version, we have to use a udi... and I don't know how to set multiple nodes on this property. Example:
if (ApplicationContext.IsReady) {
var contentService = ApplicationContext.Current.Services.ContentService;
var thing1 = contentService.GetById(2495).GetUdi();
var thing2 = contentService.GetById(2276).GetUdi();
var pageResults = contentService.GetChildren(1220);
if (pageResults != null && pageResults.Any()) {
foreach (var pageItem in pageResults) {
string pageName = pageItem.Name.ToLower().Trim();
if (pageName.StartsWith("thing")) {
pageItem.SetValue("Brand", thing1.ToString());
} else {
// how to get thing1 and thing2 together???
pageItem.SetValue("Brand", thing2.ToString());
}
contentService.SaveAndPublishWithStatus(pageItem);
}
}
}
Why the change and why doesn't the previous version of this code work anymore?
The change is to make moving umbraco installs easier (the old Id values change between installations - so if you moved your settings/content from say dev to live then all the links would be broken).
if your just upgrading you don't have to use the version 2 pickers - there is a setting in umbracoSettings.config that will enable the old property editors (showDeprecatedPropertyEditors), - so you can carry on with the old way.
The new way . the values are stored in a similar format, to set multiple values you need to comma separate them
content service setvalue multinode treepicker2
Previous to our upgrade to 7.6.5, we could do the following with the old multinode treepicker using the content service:
With the new version, we have to use a udi... and I don't know how to set multiple nodes on this property. Example:
Why the change and why doesn't the previous version of this code work anymore?
Hi Simon,
The change is to make moving umbraco installs easier (the old Id values change between installations - so if you moved your settings/content from say dev to live then all the links would be broken).
if your just upgrading you don't have to use the version 2 pickers - there is a setting in umbracoSettings.config that will enable the old property editors (
showDeprecatedPropertyEditors
), - so you can carry on with the old way.The new way . the values are stored in a similar format, to set multiple values you need to comma separate them
should do it (i am sure there are nicer ways)
is working on a reply...