I'm trying to publish multimedia content (images) on my server from a C# Template Building Block.
I tried the following:
// Get the component
Component c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
// Get the fields
ItemFields fields = new ItemFields(c.Content, c.Schema);
// get our Embedded schema field
EmbeddedSchemaField emb = (EmbeddedSchemaField)fields["Slide"];
// Loop
foreach (ItemFields embeddedfields in emb.Values)
{
foreach (ItemField field in embeddedfields)
{
ComponentLinkField fieldImage = field as ComponentLinkField;
if (fieldImage !=null){
Component component = fieldImage .Value;
string componentId= component.Id;
package.PushItem("ARN", package.CreateStringItem(ContentType.Text, componentId));
TcmUri uri2 = new TcmUri("tcm:126-3103-4");
StructureGroup sg = new StructureGroup(engine.GetSession(),uri2);
string replace = engine.PublishingContext.RenderedItem.AddBinary(component, sg).Url;
}
}
}
uri2
is the TCMUri of a Folder where I want the image to be published on the server and component
is the Component containing the image.
With that code, I get the following error using Template Builder:
Invalid context Publication specified in URI: New StructureGroup (parent: tcm:123-3744-2). Expecting: 123.