Deleting item from Sharepoint calendar -
i want delete item sharepoint calendar. here part of code:
microsoft.sharepoint.client.camlquery query = new microsoft.sharepoint.client.camlquery(); query.viewxml = "<view><query><where><and><eq><fieldref name='title'/><value type='text'>" + requesttitle + "</value></eq><eq><fieldref name='eventdate'/><value type='text'>" + lfrom + "</value></eq></and><and><eq><fieldref name='enddate'/><value type='text'>" + lto + "</value></eq><eq><fieldref name='falldayevent'/><value type='text'>" + boolean.truestring + "</value></eq></and></where></query></view>"; microsoft.sharepoint.client.listitemcollection listitem = calendar.getitems(query); context.load(listitem); if (listitem.count == 1) { listitem[0].deleteobject(); //context.executequery(); }
it throws exception in line
if (listitem.count == 1)
it says listitem not initialized. throws exception when pass empty query this:
microsoft.sharepoint.client.listitemcollection listitem = calendar.getitems(new microsoft.sharepoint.client.camlquery());
why? on link https://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx said should retrieve items when empty query passed.
evertyhing works adding new item calendar, here code used that:
//adding new calendar item microsoft.sharepoint.client.listitemcreationinformation item = new microsoft.sharepoint.client.listitemcreationinformation(); microsoft.sharepoint.client.listitem newitem = calendar.additem(item); newitem["title"] = requesttitle; newitem["eventdate"] = lfrom; newitem["enddate"] = lto; newitem["falldayevent"] = boolean.truestring; newitem.update();
since, have used,
microsoft.sharepoint.client
library, assuming client-side application. in client-side app, sending request server costly affair. hence, happens whenever load component, request created in background. way, can bundle multiple request 1 using load() many times. send request server, need call executequery() before checking length of listitemcollection.
microsoft.sharepoint.client.listitemcollection listitem = calendar.getitems(query); context.load(listitem); context.executequery(); // take while if (listitem.count == 1) { listitem[0].deleteobject(); context.executequery(); }
Comments
Post a Comment