I am working on a requirement where I need to create Document Library using REST API using C# code using Visual Studio.
The main problem is that I am not having SharePoint Server environment. I am just having site URL and credentials.
When I use following code to get the data from list item then that works properly. But now I want to create document library. So can any one suggest what should I change in my code so that it can create a document library. I tried various codes with POST but that are of no use for posting here.
My GET code is as follow:
SecureString passWord = new SecureString();
foreach (char c in "Password".ToCharArray())
passWord.AppendChar(c);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("SiteURL/_api/web/lists/getbytitle('ListName')/items?$select=id,LastName");
request.Method = "GET";
request.Accept = "application/json;odata=verbose";
request.ContentType = "application/json;odata=verbose";
request.Credentials = new NetworkCredential("username", passWord, "siteurl");
WebResponse response = request.GetResponse();
string base64Credentials = GetEncodedCredentials();
//Read the returned posts into an object that can be consumed by the calling application
using (response)
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
try
{
string jSON = reader.ReadToEnd();
}
catch (Exception ex)
{
throw new Exception(string.Format("An error occurred when reading the list items from SharePoint: {0}; {1}", ex.Message, ex.StackTrace));
}
}
}