1
votes

I am using Sharepoint 2013 ECM to upload new document sets to a list programatically in VB.NET/C#

I am successfully creating the document set, but can not find any documentation on how to add the properties/metadata to that uploaded document set. The Folder the document set will upload to already has the properties pre-defined. I just need to set them.

The code below creates the new document set. But there is zero information I can find on the internet on how to add properties from this. Sharepoint 2010 libraries allow the DocumentSet.Create to contain a properties field, but 2013 does not appear to.

Dim context As ClientContext = New ClientContext("URL")
            context.Credentials = New NetworkCredential("Username", "Password")

            'Get the document library in which the document set has to be created
            Dim list As List = context.Web.Lists.GetById(New Guid("dc9e7aa5-5ac3-499c-a967-fa8f04bf1c90"))                       

            'Get the parent folder where the document set has to be created
            Dim parentFolder As Folder = list.RootFolder

            'Get the "Document Set" content type by id (Document Set content type Id : 0x0120D520) for the document library
            Dim ct As ContentType = context.Web.ContentTypes.GetById("0x0120D520")
            context.Load(ct)
            context.ExecuteQuery()

            'Create a new document set
            'A new document set will be created in "Documents" library as "Test Document" under which you can add the documents
            DocumentSet.Create(context, parentFolder, dsName, ct.Id)
            context.ExecuteQuery()
2

2 Answers

2
votes

Once the document set is created, you could set its properties via list item associated with a document set

Example

Using context = New ClientContext(webUrl)
     context.Credentials = credentials

     'Create a document set
     Dim list As List = context.Web.Lists.GetByTitle("Documents")
     Dim parentFolder As Folder = list.RootFolder
     Dim ct As ContentType = context.Web.ContentTypes.GetById("0x0120D520")
     context.Load(ct)
     context.ExecuteQuery()
     Dim result = DocumentSet.Create(context, parentFolder, dsName, ct.Id)
     context.ExecuteQuery()

     'Set DocSet properties
     Dim docSetUrl = result.Value
     Dim folder = context.Web.GetFolderByServerRelativeUrl(docSetUrl)
     folder.ListItemAllFields("DocumentSetDescription") = "Orders 2016"
     folder.ListItemAllFields.Update()
     context.ExecuteQuery()

End Using

Result

enter image description here

0
votes

you have to set the properties on the Item property of the Document Set object. Like this (sorry for c# code):

DocumentSet myDocSet = DocumentSet.Create(x, x, x, x):
SPListItem myDocSetItem = myDocSet.Item;

myDocSetItem[property] = value;