HttpWebRequest contextinfoRequest =
(HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/contextinfo");
contextinfoRequest.Method = "POST";
contextinfoRequest.ContentType = "text/xml;charset=utf-8";
contextinfoRequest.ContentLength = 0;
contextinfoRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse contextinfoResponse = (HttpWebResponse)contextinfoRequest.GetResponse();
StreamReader contextinfoReader = new StreamReader(contextinfoResponse.GetResponseStream(), System.Text.Encoding.UTF8);
var formDigestXML = new XmlDocument();
formDigestXML.LoadXml(contextinfoReader.ReadToEnd());
var formDigestNode = formDigestXML.SelectSingleNode("//d:FormDigestValue", xmlnspm);
string formDigest = formDigestNode.InnerXml;
//Execute a REST request to get the list name and the entity type name for the list.
HttpWebRequest listRequest =
(HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/Web/lists(guid'" + listId + "')");
listRequest.Method = "GET";
listRequest.Accept = "application/atom+xml";
listRequest.ContentType = "application/atom+xml;type=entry";
listRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse listResponse = (HttpWebResponse)listRequest.GetResponse();
StreamReader listReader = new StreamReader(listResponse.GetResponseStream());
var listXml = new XmlDocument();
listXml.LoadXml(listReader.ReadToEnd());
//The entity type name is the required type when you construct a request to add a list item.
var entityTypeNode = listXml.SelectSingleNode("//atom:entry/atom:content/m:properties/d:ListItemEntityTypeFullName", xmlnspm);
var listNameNode = listXml.SelectSingleNode("//atom:entry/atom:content/m:properties/d:Title", xmlnspm);
string entityTypeName = entityTypeNode.InnerXml;
string listName = listNameNode.InnerXml;
//Execute a REST request to add an item to the list.
string itemPostBody = "{'__metadata':{'type':'" + entityTypeName + "'}, 'Title':'" + newItemName + "'}}";
Byte[] itemPostData = System.Text.Encoding.ASCII.GetBytes(itemPostBody);
HttpWebRequest itemRequest =
(HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/Web/lists(guid'" + listId + "')/Items");
itemRequest.Method = "POST";
itemRequest.ContentLength = itemPostBody.Length;
itemRequest.ContentType = "application/json;odata=verbose";
itemRequest.Accept = "application/json;odata=verbose";
itemRequest.Headers.Add("Authorization", "Bearer " + accessToken);
itemRequest.Headers.Add("X-RequestDigest", formDigest);
Stream itemRequestStream = itemRequest.GetRequestStream();
itemRequestStream.Write(itemPostData, 0, itemPostData.Length);
itemRequestStream.Close();
HttpWebResponse itemResponse = (HttpWebResponse)itemRequest.GetResponse();
RetrieveListItems(accessToken, listId);
Thursday, March 18, 2021
Create list item in SharePoint list using REST API
Subscribe to:
Post Comments (Atom)
Gaming » Exciting slots, live dealers, scratch cards, bingo
ReplyDeleteLive 메리트 카지노 쇼미더벳 Casino Casino in California is 우리 카지노 사이트 here! Enjoy the thrills of the best 퍼스트 카지노 casino games around with the latest LIVE 포커 고수 Dealers, Huge Slots, Multiplier Jackpots, 카지노 사이트 추천