Sharepoint - 使用列值上载文件无法加载目标中的分类字段

时间:2015-10-21 18:13:55

标签: c# sharepoint taxonomy

我正在尝试将文件从一个服务器场中的一个文档库传输到另一个服务器场。由于两者都可以从同一网络访问,我想到从源获取列值并直接将其添加到目标上的项目中。还要将文件与项目一起上传。

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

我得到例外:

  

术语存储on 中不存在给定的guid ccTarget.exceuteQuery()

0 个答案:

没有答案