Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

ListItem.Update() throws exception in app only context

$
0
0

Hi all,

Currently I'm working on an add-in for SharePoint that needs to update list items in a specific library. When I use a client context that is created with "CreateUserClientContextForSPHost", it all works fine and the list item gets updated. However, I need a client context created with "CreateAppOnlyClientContextForSPHost" and with this context, the same code throws an exception:

[ServerException: Object reference not set to an instance of an object.]
   Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) +1876
   Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() +948
   Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) +623
   Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() +47
   Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() +89
   Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() +495
   CircleSoftware.SharePoint.ConnectWeb.SharePointHelper.UpdateListitem(ClientContext clientContext, SharePointInfo sharepointInfo, RmaMetadata metadata) in D:\Development\Code\SPC\CircleSoftware.SharePoint.Connect\CircleSoftware.SharePoint.ConnectWeb\Classes\Helpers\SharePointHelper.cs:809

[Exception: An error occurred while updating listitem 'https://circlesoftwaredev.sharepoint.com/sites/Connect2KRD/Gedeelde  documenten/woonwerkverkeer.pdf' in library 'Documenten' in site 'https://circlesoftwaredev.sharepoint.com/sites/Connect2KRD': Object reference not set to an instance of an object.]
   CircleSoftware.SharePoint.ConnectWeb.SharePointHelper.UpdateListitem(ClientContext clientContext, SharePointInfo sharepointInfo, RmaMetadata metadata) in D:\Development\Code\SPC\CircleSoftware.SharePoint.Connect\CircleSoftware.SharePoint.ConnectWeb\Classes\Helpers\SharePointHelper.cs:817
   CircleSoftware.SharePoint.ConnectWeb.TestPage.TestUpdate() in D:\Development\Code\SPC\CircleSoftware.SharePoint.Connect\CircleSoftware.SharePoint.ConnectWeb\Test\TestPage.aspx.cs:54
   CircleSoftware.SharePoint.ConnectWeb.TestPage.TestButton_Click(Object sender, EventArgs e) in D:\Development\Code\SPC\CircleSoftware.SharePoint.Connect\CircleSoftware.SharePoint.ConnectWeb\Test\TestPage.aspx.cs:14
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +116
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +31
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3582

I'm completely lost as to why this exception is thrown. All across the internet I read that is doesn't matter how this context is created, as long as the user and/or app has sufficient permissions. And they both have sufficient permissions (the add-in has full control on the site collection). Also, I've checked the "app-only calls to SharePoint" flag in the app manifest.

Additional info: I am able to get list and listitem information from SharePoint throught both client contexts. It's only when I use "ListItem.Update()" that "context.ExecuteQuery()" throws the exception (in case of app-only context).

Does anyone have any idea on why this occurs and how I can solve this?

Thanks in advance for your effort!!

Best regards,
Ruud Hunnekens.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>