在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文档.
| 归档时间: |
|
| 查看次数: |
910 次 |
| 最近记录: |