i'mI'm trying to publish multimedia content (images) on my server from a C# Template building blockBuilding Block.
I tried the following :
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.
// 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, iI get the following error using template builderTemplate Builder:
Invalid context Publication specified in URI: New StructureGroup (parent: tcm:123-3744-2). Expecting: 123.
Thanks for your help and advices