4

I have a requirement of publishing only a Multimedia or Binary Component when it is published and not any other Component linked to it.I understand I need to use Custom resolver, I need to know what is the best way to find the linked components of a binary component and stop those from publishing. A code snippet will be appreciated.

Thanks.

2 Answers 2

6

If I understood your requirement correctly, while publishing the binaries dynamically, you want to avoid the dependent items to go to publishing.

So if you want to achieve it using custom resolver. One point to mention here is: In case you have multiple publishers, deploy the custom resolver to all your publishing servers as explained here.

I am sharing a simple example code, which should work for your requirement.

public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, Tridion.Collections.ISet<ResolvedItem> resolvedItems)
        {
            // Check if published item is multimedia component
            if (item is Component)
            {
                Component comp = (Component)item;
                if (comp.ComponentType == ComponentType.Multimedia)
                {
                    // Remove all resoved dependent items
                    // you can remove items selectivly as well, if needed.
                    resolvedItems.Clear();
                }
            }
}

You can also have a look here for some example code.

5

Using a custom resolver for this is quite likely to be the wrong approach. One very common reason for wanting not to resolve component links is that the resolving query is one of the heaviest database queries, so if there is no functional need for component link resolving, the system will run better without it. Unfortunately, the custom resolver technique that several people propose will not help with this, as the default resolver will already have run the query by the time the custom resolver runs, and all you are doing is throwing away the results that you don't want.

Instead, use the events system to set the IncludeComponentLinks property of the ResolveInstruction to false. To do this, subscribe to the Initiated phase of PubllishEventArgs. From PublishEventArgs you can reach the ResolveInstruction via the PublishInstruction property.

The IncludeComponentLinks Boolean gets sent all the way down to the stored procedure, giving you a much more lightweight database query, and exactly the functionality you wanted.

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.