【问题标题】:Unable to create component using Coreservice无法使用 Coreservice 创建组件
【发布时间】:2012-06-14 09:49:05
【问题描述】:

我正在尝试使用以下代码使用 coreservice 创建组件,当我执行 exe 时,出现错误“无法找到 uuid:”“64c7e56a-161d-4698-a76b-7fd96227948d:Content”。

我已经打开了链接到这个组件的架构,我也在那里看到了这个 UUID。

到目前为止,我只是尝试通过提供硬编码的文件夹、架构、标题来创建组件。

如果您能指导我如何在组件中添加字段值,那就太好了。 (例如,假设我的架构中有一个“文本”字段链接到该组件,并且我想使用相同的程序在我的组件的该字段中添加“这是文本”。

你能帮我解决这个问题吗?

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

【问题讨论】:

    标签: tridion tridion-2011


    【解决方案1】:

    你需要设置组件的内容属性。

    XmlDocument doc = new XmlDocument();

    doc.LoadXml(string.Format(@"<Content xmlns='{0}'><Test>Hello</Test></Content>",     SchemaToUse.NamespaceUri));
    
    CurrentMigrationComponent.Content = doc.DocumentElement;
    

    【讨论】:

    • 您好,您能解释一下您的回复吗? {0} 这是什么意思?如果我有更多的领域,这应该增加吗?我需要删除我的任何代码行吗?在我的程序中将你的代码行保存在哪里?
    • 架构的命名空间 uri。您必须阅读架构。您将获得访问 Schema.SchemaspaceUri 属性的命名空间uri。
    • 你不能创建没有内容的组件,这就是我们所说的。组件是您指定的字段 + Schema 中指定的内容。
    猜你喜欢
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多