Sharepoint - uploading files with column values ca

2019-06-12 04:42发布

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

0条回答
登录 后发表回答