【问题标题】:Sharepoint 2010 DocumentSets - How to Manage Programatically?Sharepoint 2010 文档集 - 如何以编程方式管理?
【发布时间】:2013-12-20 19:00:49
【问题描述】:

我是 Sharepoint 2010 的新手,但对 .Net 编程并不陌生。这是我的情况,我有大量文件要上传到带有元数据的 Sharepoint 2010。我决定编写一个 C# 类库以编程方式处理文档集。我必须使用 DocumentSets,并且我能够成功创建一个文档集。现在我陷入了以下困境:

  1. 如何检查文档集是否已存在?
  2. 如何删除文档集?

这是我创建文档集的代码:

using (SPSite site = new SPSite(spURL))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPList docs = web.Lists["Documents"];

        if (docs != null)
        {
            SPContentType docSetCT = docs.ContentTypes["Document Set"];

            if (docSetCT != null)
            {
                Hashtable docsetProps = new Hashtable();
                docsetProps.Add("New Docset", "New Docset");
                DocumentSet docSet = DocumentSet.Create(docs.RootFolder, documentSetName, docSetCT.Id, docsetProps, true);
                docs.Update();
            }
        }
    }
}

【问题讨论】:

    标签: sharepoint-2010


    【解决方案1】:

    使用文档集的辅助方法列表:

    如何检查文档集是否已存在?

    private static bool IsDocumentSetExist(SPList list,string docSetName)
    {
        var folderUrl = SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, docSetName);
        var folder = list.ParentWeb.GetFolder(folderUrl);
        return folder.Exists;
    }
    

    用法:

    var docSetExists = IsDocumentSetExist(docs, "New Docset");
    

    如何删除文档集?

    private static void DeleteDocumentSet(DocumentSet docSet)
    {
        docSet.Folder.Delete();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-25
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多