Monday, July 23, 2012

Create Document Set Programatically In SharePoint 2010

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateDocumentSet.aspx.cs" Inherits="ECM_CreateDocumentSet.Layouts.ECM_CreateDocumentSet.CreateDocumentSet" DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <h1>Document Set Creation Demo</h1>
        This page creates a new document set in the Shared Documents folder. Document
        sets enable you to manage multiple documents as one. For example, you can submit
        an entire document set as a record in a single operation. You can also apply
        metadata and permissions to every document in the set.  Before you
        can create and use document sets, you must enable the Document Sets feature at
        the site collection level. Then add the Document Set content type to the document
        library where you want to use them.
        Name: <asp:TextBox ID="nameTextbox" runat="server"></asp:TextBox>
        Description: <asp:TextBox ID="descriptionTextbox" runat="server"></asp:TextBox>
    <asp:Button ID="createDocSetButton" OnClick="createDocSetButton_Click" runat="server" Text="Create Document Set" />
    <asp:Label ID="resultLabel" runat="server" Text=""></asp:Label>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    ECM Document Set Creation
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
    ECM Document Set Creation
using System;
using System.Collections;
using Microsoft.Office.DocumentManagement.DocumentSets;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace ECM_CreateDocumentSet.Layouts.ECM_CreateDocumentSet
    /// <summary>
    /// This application page creates a document set based on the default document set
    /// content type.
    /// </summary>
    /// <remarks>
    /// You must have enabled the site collection level Document Sets feature, and added
    /// the Document Set content type to the document library, before you can create
    /// document sets.
    /// </remarks>
    public partial class CreateDocumentSet : LayoutsPageBase
        protected void Page_Load(object sender, EventArgs e)
        protected void createDocSetButton_Click(object sender, EventArgs e)
            //Get the Shared Documents document library
            SPWeb currentWeb = SPContext.Current.Web;
            SPDocumentLibrary sharedDocsLib = (SPDocumentLibrary)currentWeb.Lists["Shared Documents"];
            //You can use a hashtable to populate properties of the document set
            Hashtable docsetProperties = new Hashtable();
            docsetProperties.Add("Name", nameTextbox.Text);
            docsetProperties.Add("DocumentSetDescription", descriptionTextbox.Text);
            //Create the document set
                DocumentSet newDocSet = DocumentSet.Create(sharedDocsLib.RootFolder,
                    nameTextbox.Text, sharedDocsLib.ContentTypes["Document Set"].Id,
                    docsetProperties, true);
                resultLabel.Text = "Document set created";
            catch (Exception ex)
                resultLabel.Text = "An error occurred: " + ex.Message;


Featured Post

Azure Scripts

 Azure Scripts: Azure > Storage account > File shares > SMB File share To connect to this Azure file share from Windows, run the Po...

Popular posts