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

时间:2012-07-11 12:48:38

标签: tridion

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

2 个答案:

答案 0 :(得分: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));
        }
    }
}

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

Engine.PublishingContext.RenderedItem.AddBinary(img, structureGroup); 

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

答案 1 :(得分:1)

你可以通过几种方式做到这一点:

1)静态发布,即创建一个结构组(即将在服务器上创建的文件夹)并在其中创建一个页面。您的页面需要一个元数据架构,该架构采用多个多媒体组件链接,以便您可以将图像添加到页面的元数据中。您需要为此页面构建一个页面模板,该页面将具有TBB,该TBB从页面元数据中获取多媒体组件,并使用Engine.AddBinary方法将图像添加到包中并与页面一起发布(页面输出可以是一些虚拟的东西)。请注意,如果您有大量图像,则会对性能产生影响。

2)动态发布:如果您有代理,则可以配置文件系统发布。然后创建链接到图像架构的动态组件模板。内部使用带有engine.AddBinary方法的TBB,用于给定MM组件将图像作为动态组件表示发布到给定结构组。

相关问题