2

Trying to create a list item in the SharePoint list in a batch of 5 using Visual Studio but the clientContext.ExecuteQuery() throws exception and only create 1 list item.

var url = "calling a webservice";
var content = syncClient.DownloadString(url);
JsonResultInfo jsri = new JsonResultInfo();
List<JsonResult> dynJson = JsonConvert.DeserializeObject<List<JsonResult>>(content);

//Connect to SharePoint and read Idea list

  • List item

    CamlQuery query = new CamlQuery(); string siteUrl = "sharepoint site list url"; ClientContext clientContext = new ClientContext(siteUrl); SP.List oList = clientContext.Web.Lists.GetByTitle("LIST NAME"); ListItemCollection listItems = oList.GetItems(query); clientContext.RequestTimeout = -1; clientContext.Load(listItems); clientContext.ExecuteQuery();| oListItem["title] = item.title; oListItem["body"] = item.body; oListItem.Update(); itemCount++;

get itemcount to 5 , then

clientContext.ExecuteQuery(); // the execption is thrown saying A first chance exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in

Microsoft.SharePoint.Client.Runtime.dll

ps: Added Request timeout , and gave this exception

1 Answer 1

1

Please increase RequestTimeOut of ClientContext as shown below:

clientContext.RequestTimeout = -1;

Hope it works for you.

5
  • Hi, i added it. it thrw another error "A first chance exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll ". i have modified the question. kindly help! Commented May 12, 2017 at 12:47
  • Didn't understood please elaborate more in details Commented May 12, 2017 at 12:50
  • 1
    You will need to put clientContext.ExecuteQuery(); after each item update.because SharePoint didn't understood currently which item going to update. Commented May 12, 2017 at 12:55
  • i am pulling the data from a web service and comparing the data present in the share point and which ever data that is not present in share point list , is added to the list as a new item. Commented May 12, 2017 at 12:55
  • still throwing Microsoft.SharePoint.Client.ServerException Commented May 16, 2017 at 6:40

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.