Using CSOM in Visual C# how can we add a new field in Sharepoint 2013 document library and also how can we upload the files to document library in Sharepoint 2013. I could not get the document library details in CSOM code but I could get the reference of newly created list and able to edit the list by adding new field to it.
How can I do it for a document Library.
Vijay SPosted Apr 8, 2015, 10:06 AM
SPWeb web = new SPSite(/*your web url or variable*/).OpenWeb();
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists[/*here your document library*/];
docLib.Fields.Add("columName1", SPFieldType.Text, false);
string attrib;
SPFolder folder = web.GetFolder(/*your dest folder here*/);
SPFile file = folder.Files.Add(/*your properties here*/);
file.Item["columName1"] = attrib;
file.Item.Update();
Mark as Answer if it is helpful to you. Thanks in advance.