How to update metadata with uploading file to sharepoint Library using sharepoint Rest API? I am adding my complete code.
I am new in sharepoint rest.
I am able to uploading file is working but I need metadata updata also please help me. I need urgent pls help. I am trying last one week. I am adding my complete code. how to update metadata in this code.
______________________________________________________________________________________________
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string filePath = @”C:\test.txt”; //File to be uploade
string siteurl = “http://site”; //site on which file needs to be uploaded (don’t put / at end)
string documentlibrary = “Documents”; //Document library where file needs to be uploaded
NetworkCredential credentials = new System.Net.NetworkCredential(“username”, “password”, “domain”);
int itemID=getLastItemID(siteurl,documentlibrary,credentials);
console.writeLine(“Last Item id is “+itemID);
console.Read();
}
internal static int getLastItemID(string siteurl,string documentlibrary,NetworkCredential cred)
{
int newFormDigest1=0;
HttpWebRequest endpointRequest1 = (HttpWebRequest)HttpWebRequest.Create(siteurl + “/_api/lists/GetByTitle(‘”+documentlibrary+”‘)/items?$top=1&$orderby=Id%20desc”);
endpointRequest1.Method=”GET”;
endpointRequest1.ContentLength=0;
endpointRequest1.Credentials=cred;
endpointRequest1.Accept=”application/json;odata=verbose”;
try{
HttpWebResponse endpointResponse1=(HttpWebResponse)endpointRequest1.GetResponse();
}
catch(Exception ex){
Console.writeLine(ex.Message);
}
try{
WebResponse webresponse=endpointRequest1.getResponse();
Stream webStream = webResp.GetResponseStream();
StreamReader responseReader = new StreamReader(webStream);
string response = responseReader.ReadToEnd();
var j = JObject.Parse(response);
var jObj = (JObject)JsonConvert.DeserializeObject(response);
foreach(var child in jObj[“d”][“results”].Children())
{
newFormDigest1=((dynamic)child).Id;
}
responseReader.close();
}
catch(Exception ex){
Console.writeLine(ex.Message);
}
return newFormDigest1;
}
}
Thanks .