Sharepoint 2013如何向正在创建的文档集添加属性

时间:2016-04-29 05:29:11

标签: vb.net sharepoint sharepoint-2013

我正在使用Sharepoint 2013 ECM在VB.NET / C中以编程方式将新文档集上传到列表#

我已成功创建文档集,但找不到有关如何将属性/元数据添加到上载文档集的任何文档。文档集将上传到的文件夹已经具有预定义的属性。我只需要设置它们。

下面的代码创建了新的文档集。但是,我可以在互联网上找到关于如何从中添加属性的零信息。 Sharepoint 2010库允许DocumentSet.Create包含属性字段,但2013似乎不会出现。

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 个答案:

答案 0 :(得分:2)

创建文档集后,您可以通过与文档集关联的列表项设置其属性

示例

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

<强>结果

enter image description here

答案 1 :(得分:0)

您必须在文档集对象的Item属性上设置属性。像这样(抱歉c#代码):

public class MyAppContext : DbContext 
    { 
        public DbSet<Organisation> Organisations { get; set; } 
    }