In SDL Tridion 2009, you need to use the TOM (Interop) API to create new items, this differs from the TOM.NET API (since the TOM.NET API in 2009 was read-only).
So you have to work from the TDSE
like this:
using System.Runtime.InteropServices;
using Tridion.ContentManager.Interop.TDS;
using Tridion.ContentManager.Interop.TDSDefines;
using ItemType = Tridion.ContentManager.Interop.TDSDefines.ItemType;
{
TDSE tdse = new TDSE();
tdse.Impersonate(@"domain\user");
tdse.Initialize();
// read Schema tcm:1-3-8
Schema schema = (Schema)tdse.GetObject("tcm:1-3-8", EnumOpenMode.OpenModeView, Constants.URINULL, XMLReadFilter.XMLReadData);
// create new Component, in Folder "tcmtcm:1-2-2"2
Component comp = (Component)tdse.GetNewObject(ItemType.ItemTypeComponent, "tcm:1-2-2", Constants.URINULL);
comp.Title = "new title";
comp.Schema = schema;
// etc. follow the examples in the TOM API guide, don't mix this with the TOM.NET API
comp.Save(true);
if (comp.Info.IsCheckedOut)
{
comp.CheckIn();
}
// release objects
ReleaseCom(schema);
ReleaseCom(comp);
ReleaseCom(tdse);
}
private static void ReleaseCom(object instance)
{
if (instance != null)
{
try
{
Marshal.ReleaseComObject(instance);
}
catch
{
/* log potential memory leak */
}
}
}
You really need to only look at the TOM API guide, and don't even include the TOM.NET DLLs as references in our project, since that will just confuse you.
Note the
Component
class used in your example and mine are different, I'm using aTridion.ContentManager.Interop.TDS.Component
, and that is also what you need to use. Don't use aTridion.ContentManager.CommunicationManagement.Component
, since that will be a read-only object.
For more examples on how to work with the TOM API, you could take a look at the old powertools, these are written in ASP VBScript, and you will need to translate that to TOM Interop (C#), but it should already give you a general idea.