I am trying to create component using coreservice using the below code, and when i execute the exe, am getting the error "unable to find the uuid:""64c7e56a-161d-4698-a76b-7fd96227948d:Content".
I have opened the schema which am linking to this component, and i seen this UUID over there also.
as of now am just trying to create a component by providing the folder, schema, title as hard corded.
if you can guide me how to add field value also in component, that would be great. (For example assume that i have a field "Text" in my schema which am linking to this component, and i want to add "This is the Text" in this field of my component using the same program.
can you please help me out on this?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DctmToSDLMigration.SDLCoreServiceReference;
namespace DctmToSDLMigration
{
class Program
{
static DctmToSDLMigration.SDLCoreServiceReference.SessionAwareCoreService2010Client client = new SessionAwareCoreService2010Client();
static ReadOptions readoptions = new ReadOptions();
static void CreateComponent()
{
try
{
string TargetFolderTcmId = "tcm:148-1263-2";
string LinkSchemaTcmId = "tcm:148-11460-8";
ComponentData CurrentMigrationComponent = client.GetDefaultData(ItemType.Component, TargetFolderTcmId) as ComponentData;
LinkToSchemaData SchemaToUse = new LinkToSchemaData();
SchemaToUse.IdRef = LinkSchemaTcmId.ToString();
CurrentMigrationComponent.Schema = SchemaToUse ;
CurrentMigrationComponent.Title = "Test component";
client.Create(CurrentMigrationComponent, readoptions);
Console.WriteLine(CurrentMigrationComponent.Id);
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadLine();
}
}
static void Main(string[] args)
{
CreateComponent();
}
}
}
You need to set the Content Property of the Component.
XmlDocument doc = new XmlDocument();
doc.LoadXml(string.Format(@"<Content xmlns='{0}'><Test>Hello</Test></Content>", SchemaToUse.NamespaceUri));
CurrentMigrationComponent.Content = doc.DocumentElement;