Sharepoint - uploading files with column values can't load Taxonomy fields in target

谁说胖子不能爱 提交于 2019-12-08 11:56:01

问题


I am trying to transfer files from one document library on one farm to another. Since both are accessible from same network, I thought of getting column values from source and directly add it into a item on destination. Also upload the file along with the item.

    List list = ccSource.Web.Lists.GetByTitle("Source Library");
    ccSource.ExecuteQuery();  // ccSource is initialized with source Site collection
    CamlQuery query = new CamlQuery();
    ListItemCollection itemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());  //Query can also be selective
    ccSource.Load(list);
    ccSource.Load(itemCollection);
    ccSource.ExecuteQuery();
    ccSource.Load(ccSource.Web);
    string[] coloumnsList = System.IO.File.ReadAllLines(@"E:\Coloumns.txt");
    foreach (ListItem item in itemCollection)
    {
    ClientContext ccTarget. = new ClientContext("http://TargetSC/sites/mysite");
    ccTarget.Credentials = new NetworkCredential("username", "pass", "domain");
    ccTarget.ExecuteQuery();
    var targetList = ccTarget.Web.Lists.GetByTitle("TargetLibrary");
    string diskFilePath = @"E:\downloadedFile.docx";   //I have skipped the download code
    var fileInfo1 = new FileCreationInformation
    {
        Url = System.IO.Path.GetFileName(diskFilePath),
        Content = System.IO.File.ReadAllBytes(diskFilePath),
        Overwrite = true
    };
    var file = targetList.RootFolder.Files.Add(fileInfo1);
    var itemTar = file.ListItemAllFields;

    //update list values
    foreach (var allFields in item.FieldValues)
    {
        if (allFields.Key == "FileLeafRef" || checkColoumn(coloumnsList,allFields.Key))
         itemTar[allFields.Key] = allFields.Value;

    }


    itemTar.Update();
    ccTarget.ExecuteQuery();   //Exception here
    }
     public static bool checkColoumn(string[] arr,string query)
    {
        bool flag = false;
        for (int i = 0; i < arr.Length; i++)
        {
            if (arr[i].Equals(query))
            {flag = true; break;}
        }
        return flag;
    }

I am getting exception:

The given guid does not exist in the term storeon ccTarget.exceuteQuery()

来源:https://stackoverflow.com/questions/33266404/sharepoint-uploading-files-with-column-values-cant-load-taxonomy-fields-in-ta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!