Question

From a C# TBB used by a Modular Page Template in SDL Tridion 2011, is it possible to access the User object who initiated the Publishing action?

Looking at the TOM.NET 6 Programmers Reference Guide, it seems that the property I need is the Creator property of the PublicationTransaction object, but I can’t find a way to access that from a C# TBB, I don’t see an obvious way to get the current PublicationTransaction from the engine or package objects, and I can only find a way to get a list of PublicationTransaction objects using the PublishEngine object.

Any advice would be greatly appreciated.

Was it helpful?

Solution

Have a look at these two blog posts from Mihai Cadariu:

With those two you should be able to find what you need.

The basic function you need in your TBB is this:

public PublishTransaction GetPublishTransaction(Engine engine)
{
    String binaryPath = engine.PublishingContext.PublishInstruction.
                                         RenderInstruction.BinaryStoragePath;
    Regex tcmRegex = new Regex(@"tcm_\d+-\d+-66560");
    Match match = tcmRegex.Match(binaryPath);

    if (match.Success)
    {
        String transactionId = match.Value.Replace('_', ':');
        TcmUri transactionUri = new TcmUri(transactionId);
        return new PublishTransaction(transactionUri, engine.GetSession());
    }

    return null;
}

It might also be worth noting that the property engine.PublishingContext.PublishInstruction.RenderInstruction.BinaryStoragePath will return something different when rendering the coder in PreviewMode or from the Template Builder compared to when the code is running in the Publisher. To see the PublishTransaction URI in the BinaryStoragePath, you must attach your Visual Studio TBB Debug Project to the TcmPublisher.exe process in order for there to actually be a PublishTransaction object present, otherwise the BinaryStoragePath will just contain a generic path like ../preview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top