Search code examples
c#sharepoint-2013metadatasharepoint-clientobject

Create new Wiki with Metadata


I am trying to create new Enterprise Wiki with Client Library in C#. I have some issue with adding Categories. On the web page I can create WikiPage and easily add our custom Categories. But it wont work with C#. Here is my code:

        for(int i = 0; i < SourceItemCol.Count; i++)
        {
            SP.ListItem sourceItem = SourceItemCol[i];
            string pageName = sourceItem["FileLeafRef"].ToString();
            //samotne pridani wikiPage na wikinu
            SP.File item = targetList.RootFolder.Files.AddTemplateFile(@"/Stranky%20wikiwebu/" + pageName/*+".aspx"*/, SP.TemplateFileType.WikiPage);
            SP.ListItem newItem = item.ListItemAllFields;

            newItem["WikiField"] = prepisTelo(sourceItem["WikiField"].ToString());
            newItem["Wiki_x0020_Page_x0020_Categories"] = sourceItem["Categories_x0020_Wiki"];
            newItem.Update();

            targetList.Update();

        }
        targetContext.ExecuteQuery();
        targetContext.Dispose();

The thing is, I got new WikiPage on the Sharepoint Wiki with correct body, but Categories dissapear. So I am asking, do someone here have experience with this? Thank you for your answers.

P.S. The whole idea is to migrate old company WikiPages on new Sharepoint server wich is using Enterprise Wiki.


Solution

  • Well I solved this problem. I was copying bad FieldValues

    newItem["e1a5b98cdd71426dacb6e478c7a5882f"] = sourceItem.FieldValues["c24e0d7655d94d68baa9cb82e45ea847"];
    

    work well.