Sunday 15 April 2012

Using SharePoint REST to add list item using C# -



Using SharePoint REST to add list item using C# -

i have application hosted on 1 server that's not part of sharepoint farm. need to post new list item sharepoint list. default sharepoint zone (where posted to) configured utilize claims authentication, integrated windows authentication.

the identity application running under has total administrative access on list i'm trying post to. every time post "403 forbidden" error. if remove endpointrequest.credentials line 401 error.

var info = "{'__metadata':{'type':'sp.data.speciallistitem'}, 'special':'" + txtspecial + "'}"; httpwebrequest endpointrequest = (httpwebrequest)httpwebrequest.create("http://portal/_api/web/list/getbytitle('special')"); endpointrequest.credentials = credentialcache.defaultnetworkcredentials; endpointrequest.method = "post"; endpointrequest.accept = "application/json;odata=verbose"; endpointrequest.contenttype = "application/json;odata=verbose"; endpointrequest.contentlength = data.length; streamwriter author = new streamwriter(endpointrequest.getrequeststream()); writer.write(data); writer.flush(); using (httpwebresponse endpointresponse = (httpwebresponse)endpointrequest.getresponse()) { using (streamreader reader = new streamreader(endpointresponse.getresponsestream())) { string result = reader.readtoend(); } }

c# rest sharepoint-2013

No comments:

Post a Comment