3

enter image description here

    public void FamilykeywordHTML()
    {
        string domainName = System.Configuration.ConfigurationSettings.AppSettings["domainName"];
        string userName = System.Configuration.ConfigurationSettings.AppSettings["userName"];
        string passowrd = System.Configuration.ConfigurationSettings.AppSettings["passowrd"];
        timestamp = DateTime.Now.ToString("dd:MM:yy h:mm:ss tt").Replace(":", "_").Replace(" ", "");
        client = CoreServiceClientFactory.GetClient();
        string CategoryId = "tcm:13-36761-512";
        CategoryData category = (CategoryData)client.Read(CategoryId, new ReadOptions());
        string[] tcmList = System.IO.File.ReadAllLines(Environment.CurrentDirectory + "\\" + "familykeywordHTMLmeta.txt");
        if (category != null)
        {
            int i = 0;
            foreach (var title in tcmList)
            {
               // string keywordTitle = title;
                string componenttcmid = title.Split('#')[0];
                string keywordTitle = title.Split('#')[1];
                //KeywordData keyword = (KeywordData)client.GetDefaultData(ItemType.Keyword, category.Id, new ReadOptions()) as KeywordData;
                var keyword = client.Read(keywordTitle, new ReadOptions()) as KeywordData;
                keyword.MetadataSchema = new Tridion.ContentManager.CoreService.Client.LinkToSchemaData { IdRef = "tcm:13-145242-8", Title = "KeyWord Meta Schema" };
                keyword.Metadata = "<Metadata xmlns=\"uuid:b001b7a9-0eea-4b27-9795-8d81ea612967\" >"+componenttcmid;
                 keyword = (KeywordData)client.Save(keyword, new ReadOptions()) as KeywordData;
                //client.Save(keyword.Metadata, new ReadOptions());
                Console.Write(i);
                i++;
            }
        }

Here i need to tag a HTML meta in field "add componnet link to home page of the keyword"

1 Answer 1

2

I'd recommend you go over this code repository which describes how to change any content or metadata here: https://github.com/TridionPractice/tridion-practice/wiki/ChangeContentOrMetadata.

But to give you an idea, you'd do something similar to this:

    // Read the component you want to add
    ComponentData componentData = (ComponentData)client.Read("tcm:xx-xx-16", null);

    // Read the metadata schema
    SchemaData meta = (SchemaData)c.Read("tcm:12-145242-8", new ReadOptions());

    string metadataContent = "<Metadata xmlns=\"" + meta.NamespaceUri + "\">" +
                                  "<metadataField1 xmlns:xlink=\"http://www.w3.org/1999/xlink\"" +
                                       "xlink:href=\"" + componentData.Id + "\"" + "xlink:title=\"" + componentData.Title + "\"" + 
                                  "</metadataField1>" + 
                             "</Metadata>"; 
    keyword.Metadata = metadataContent;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.