DocumentSet.Create method (SPFolder, String, SPContentTypeId)
Creates a new DocumentSet object.
Namespace: Microsoft.Office.DocumentManagement.DocumentSets
Assembly: Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)
Syntax
'Declaration
Public Shared Function Create ( _
parentFolder As SPFolder, _
name As String, _
ctid As SPContentTypeId _
) As String
'Usage
Dim parentFolder As SPFolder
Dim name As String
Dim ctid As SPContentTypeId
Dim returnValue As String
returnValue = DocumentSet.Create(parentFolder, _
name, ctid)
public static string Create(
SPFolder parentFolder,
string name,
SPContentTypeId ctid
)
Parameters
parentFolder
Type: Microsoft.SharePoint.SPFolderThe folder in which to create the new DocumentSet object.
name
Type: System.StringThe name of the new DocumentSet object.
ctid
Type: Microsoft.SharePoint.SPContentTypeIdThe ID of the content type to be used for the new document set to be created. The ID must be a content type that inherits from the base DocumentSet content type.
Return value
Type: System.String
The URL to the new DocumentSet object.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | The parent folder parameter is a null reference (Nothing in Visual Basic). |
InvalidOperationException | A folder with that name already exists. |
Remarks
This version of the Create method always provisions default contents for the content type, if any.
This method tries to assign any values found in the hash table to the appropriate fields in the new DocumentSet object. The values are copied to the new object only if they are valid fields present in the content type. Values for unknown fields are ignored.
Examples
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.DocumentSet; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ClientContext ctx = new ClientContext("https://localhost/"); Web targetWeb = ctx.Web; List targetList = targetWeb.Lists.GetByTitle("docsets"); ContentTypeCollection listContentTypes = targetList.ContentTypes; ctx.Load(listContentTypes, types => types.Include (type => type.Id, type => type.Name, type => type.Parent)); var result = ctx.LoadQuery(listContentTypes.Where (c => c.Name == "Document Set")); ctx.ExecuteQuery(); ContentType docsetCT = result.First(); ContentTypeId ctid = docsetCT.Id; DocumentSet.Create(ctx, targetList.RootFolder, "wsDocset", ctid); ctx.ExecuteQuery(); } } }