2016-04-29 53 views
1

我使用SharePoint 2013 ECM上傳新的文檔集到列表中編程VB.NET/C#的Sharepoint 2013如何將屬性添加到文檔集

我成功地創建文檔集,但不能找到關於如何將屬性/元數據添加到上傳的文檔集的任何文檔。文檔集將上傳到的文件夾已經具有預定義的屬性。我只需要設置它們。

下面的代碼創建新的文檔集。但是我可以在互聯網上找到關於如何添加屬性的零信息。 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

一旦文檔集創建後,您可以設置通過與文檔相關聯的列表項的屬性設置

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

+0

我收到錯誤消息:「Column'App No'不存在,它可能已被其他用戶刪除。」有什麼建議麼? – Cyassin

+0

可能發生這種錯誤,因爲提供的列名稱'App No'對應於它的顯示名稱,但是'ListItemAllFields'預計字段內部名稱,所以嘗試指定其內部名稱 –

+0

感謝Vadim, 我沒有訪問內部名稱我在週末沒有與客戶溝通的地點工作,也無法訪問這些信息。 我能夠使用folder.Properties.Item(「App No」)=「blah」來解析。只是試圖理解爲什麼工作,該方法是否接受顯示名稱? 非常感謝能夠讓我完成項目的其他代碼。 – Cyassin

0

您必須設置文檔集對象的Item屬性的屬性。像這樣(爲C#代碼抱歉):

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

myDocSetItem[property] = value; 
+0

謝謝,但我使用Sharepoint 2013,並沒有使用允許DocumentSet對象從DocumentSet.Create()返回的客戶端工具() – Cyassin

+2

ok,然後使用Vadim發佈的示例。您應該將DocumentSet作爲ListItem使用 – Verthosa

相關問題