我正在尝试使用以下代码使用coreservice创建组件,当我执行exe时,我收到错误“无法找到uuid:”“64c7e56a-161d-4698-a76b-7fd96227948d:Content”。< / p>
我已经打开了链接到这个组件的模式,我也在那里看到了这个UUID。
截至目前,我只是尝试通过提供文件夹,架构,标题来创建组件。
如果你可以指导我如何在组件中添加字段值,那就太棒了。 (例如,假设我的架构中有一个字段“Text”,它链接到此组件,我想使用相同的程序在我的组件的这个字段中添加“This is the Text”。
你可以帮我解决这个问题吗?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();
}
}
}
答案 0 :(得分:5)
您需要设置组件的内容属性。
XmlDocument doc = new XmlDocument();
doc.LoadXml(string.Format(@"<Content xmlns='{0}'><Test>Hello</Test></Content>", SchemaToUse.NamespaceUri));
CurrentMigrationComponent.Content = doc.DocumentElement;
doc.LoadXml(string.Format(@"<Content xmlns='{0}'><Test>Hello</Test></Content>", SchemaToUse.NamespaceUri));
CurrentMigrationComponent.Content = doc.DocumentElement;