I am trying to create a new Bundle in the Event System. However, I get the following error message: Unable to save item. Unexpected namespace URI: uuid:b2054ef9-904f-49d8-8b7f-40523bb88536. Expecting: http://www.sdltridion.com/ContentManager/Bundle
I do not see a namespace property on the bundle object. I am thinking to use UpdateXML and change the namespace - but it feels wrong and feels like Tridion should be setting the correct namespace for me.
Is there another way to set this namespace?
Here is my code:
using System;
using Tridion.ContentManager;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.Extensibility.Events;
namespace EventSystemBundles
{
[TcmExtension("AutoCreateBundle")]
public class AutoCreateBundle : TcmExtension
{
public AutoCreateBundle()
{
Subscribe();
}
public void Subscribe()
{
// InitLog();
// OnComponentSavePre
EventSystem.Subscribe<Component, SaveEventArgs>(OnComponentSavePre, EventPhases.Initiated);
}
private static void OnComponentSavePre(Component comp, SaveEventArgs args, EventPhases phase)
{
string bundleFolderUri = "tcm:11-44-2"; // read from config or folder meta later...
string bundleTypeSchemaUri = "tcm:11-461-8";
Session session = comp.Session;
try
{
TcmUri uri = new TcmUri(bundleFolderUri);
Bundle bundle = new Bundle(session, uri);
bundle.Title = "Bundle for " + comp.Title;
Schema bundleSchema = (Schema)session.GetObject(bundleTypeSchemaUri);
bundle.TypeSchema = bundleSchema;
bundle.Save();
//uuid:b2054ef9-904f-49d8-8b7f-40523bb88536. Expecting: http://www.sdltridion.com/ContentManager/Bundle
}
catch (Exception ex)
{
throw ex;
}
comp.Title = "a " + comp.Title;
}
}
}