如何使用C#TBB从内容管理器发布图像文件夹?

Pri*_*nku -1 tridion

我想将所有图像从内容管理器中的一个文件夹移动到服务器上的一个文件夹,如何使用C#TBB进行操作?

Bar*_*man 5

在SDL Tridion World上,您可以找到一组有用的模板构建块,其中包含以下解决方案:http://sdltridionworld.com/community/extension_overview/useful_tbbs.aspx

请参阅#5:获取CSS图像 - 发布特定CMS文件夹中的所有图像.

以下是该解决方案中的代码片段,以了解其完成方式.

Filter filter = new Filter();
filter.Conditions["ItemType"] = ItemType.Component;
filter.Conditions["Recursive"] = false;
foreach (Component img in folder.GetItems(filter))
{
    if (img.ComponentType == ComponentType.Multimedia)
    {
        string filename = Utilities.GetFilename(img.BinaryContent.Filename);
        Item item = package.GetByName(filename);
        bool push = true;
        if (item != null)
        {
            Logger.Debug("An item with the same name exists in the package");
            KeyValuePair<string, string> pair = new KeyValuePair<string,string>("TCMURI", img.Id.ToString());
            if (item.Properties.Contains(pair))
            {
                Logger.Debug("An item with the same uri exists in the package, we will not push it twice to the package.");
                push = false;
            }
        }
        if(push)
        {
            Logger.Debug(String.Format("Pushing item {0} to the package", filename));
            package.PushItem(filename, package.CreateMultimediaItem(img.Id));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以调用AddBinary并指定您希望它发布的Structure组,而不是将项目推送到包中并允许它由Default Finish Actions发布.

Engine.PublishingContext.RenderedItem.AddBinary(img, structureGroup); 
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅TOM.NET API文档.