3

Could somebody please explain to me how to manipulate publishing restrictions from a code. I would like to be able to mark some certain versions as Publishable/NonPublishable in a similar way as it could be done in PublishingSettings window: enter image description here

In API, I can see few methods, which looks like similar to this functionality available in UI, however their signatures are not very self-explaining. For instance there is something like:

myItem.Versions.GetLatestVersion().Publishing.IsPublishable(DateTime date, bool checkAncestors)
myItem.Versions.GetLatestVersion().Publishing.HideVersion

or myItem.Versions.GetLatestVersion().Publishing.NeverPublish, which obviously is not what I need.

We are lucky to have Sitecore 7.5 and I couldn't find anything relevant on SDN (maybe checked wrong documents though)

Thanks in advance.

1 Answer 1

6

It is HideVersion field which you want to use, e.g.:

var itemVersions = item.Versions.GetVersions();

var notPublishableVersion = itemVersions[i];
notPublishableVersion.Editing.BeginEdit();
notPublishableVersion[FieldIDs.HideVersion] = "1";
notPublishableVersion.Editing.EndEdit();

var publishableVersion = itemVersions[j];
publishableVersion.Editing.BeginEdit();
publishableVersion[FieldIDs.HideVersion] = string.Empty;
publishableVersion.Editing.EndEdit();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.