I was wondering if there's a way before creating a component to check for component links either from the fields of the component or through RTF.
I'm using the following code that is creating a copy of existing components. The aim is to take components from one publication and copy them to another programmatically. Whilst doing this I need to check the contents of every component for component links and recreate them too
The code below isn't complete yet as I still need to change the location of the component to be that of the target publication but you will get the jist of where the component fields are coming from.
public string Create(CoreServiceClient client, string componentId)
{
var compData = (ComponentData)client.Read(componentId, new ReadOptions());
var component = (ComponentData)client.GetDefaultData(ItemType.Component, compData.LocationInfo.OrganizationalItem.IdRef);
component.Id = "tcm:0-0-0";
component.Title = compData.Title;
component.Content = compData.Content;
component.Schema.IdRef = compData.Schema.IdRef;
try
{
component = (ComponentData)client.Create(component, new ReadOptions());
}
catch (Exception ex)
{
Console.WriteLine("Unable to create component: " + ex);
}
return component.Id;
}
Is there a way I can target individual fields and get out tcm ids of component links?
The component links could come from either a RTF or individual fields in the component. So I guess I'd need to target the component.Component field and check for tcm ids here?
Many thanks