Skip to main content
added link to old powertools for TOM API examples
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

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 a Tridion.ContentManager.Interop.TDS.Component, and that is also what you need to use. Don't use a Tridion.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.

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 "tcm:1-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();
  }

  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.

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.

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 tcm:1-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 a Tridion.ContentManager.Interop.TDS.Component, and that is also what you need to use. Don't use a Tridion.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.

added link to old powertools for TOM API examples
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

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 "tcm:1-2-2"
  Component comp = (Component)tdse.GetNewObject(ItemType.ItemTypeComponent, "tcm:1-2-2", "tcm:0-1-1"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();
  }

  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.

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.

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 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();

  Schema schema = (Schema)tdse.GetObject("tcm:1-3-8", EnumOpenMode.OpenModeView, Constants.URINULL, XMLReadFilter.XMLReadData);
  Component comp = (Component)tdse.GetNewObject(ItemType.ItemTypeComponent, "tcm:1-2-2", "tcm:0-1-1");

  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();
  }

  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.

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 "tcm:1-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();
  }

  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.

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.

Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

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 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();

  Schema schema = (Schema)tdse.GetObject("tcm:1-3-8", EnumOpenMode.OpenModeView, Constants.URINULL, XMLReadFilter.XMLReadData);
  Component comp = (Component)tdse.GetNewObject(ItemType.ItemTypeComponent, "tcm:1-2-2", "tcm:0-1-1");

  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();
  }

  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.