Creating a Custom New Document Set Form

The form that is used to create new document sets is located in _layouts of the SharePoint server. This means there is only one form for every document set content type to use. In some cases a custom form may be needed. With a custom form you could automatically fill in metadata or do conditional formatting so only certain fields are displayed depending on what options a user selects. All sorts of possibilities for creating a highly customized document set page open up.

On the document set content type there is a property called NewFormUrl, changing this property will let you specify what new form the content type uses. This allows you to specify a custom new form per document set content type. But before changing this property, a new form must be created. A new aspx page must be created and it can be stored in _layouts, or in a folder in _layouts. If you store the form inside a folder you need to add a web.config file to include the document set assembly, which is required to use the document set object model needed to create a document set.

Here is an example of a basic customized new document set page.

 

CustomNewDocSet.aspx
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="CustomNewDocset.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="https://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <asp:Literal ID="litList" runat="server" />
    <asp:Literal ID="litCt" runat="server" />
</body>
</html>

And this is an example of the code behind page.

CustomNewDocSet.aspx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
  SPList list = SPContext.Current.List;
  litList.Text = list.Title;
  SPContentTypeId ctid = new SPContentTypeId(Request.QueryString.GetValues("ContentTypeId")[0]);
  SPContentType ct = list.ContentTypes[ctid];
  litCt.Text = ct.Name;
    }
}

This is the configuration file that must be placed in the folder that contains the custom new document set aspx page. The config file is needed, otherwise the document set object model cannot be accessed. References can also be added other assemblies as needed. If the custom new document set page is placed in the root of _layouts rather than in a folder then this web.config file is not needed.

Web.Config
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false">
<assemblies>
<add assembly="Microsoft.Office.DocumentManagement, Version=14.0.0.0, Culture=neutral, PublicKeyToken=94DE0004B6E3FCC5"/>
</assemblies>
</compilation
</system.web>
</configuration>

In order to use the custom new document set page the URL for the document set content type must be updated. This is an example Powershell script that can be used. Pass in the URL to the site that contains the document set content type to be changed. The appropriate content type ID of the content type to be changed should be specified for ctid. This will then update the property NewFormUrl to use the customized new document set page rather than the out of box one. $siteurl should be the URL that has the custom document set content type. $ctid is the content type ID of the document set that is being modified. $contentType.NewFormUrl is the location in relation to _layouts that contains the custom new document set form.

ChangeNewDocSetPage.ps1
$siteUrl = "https://mysite"
$ctid = "0x0120D520"
param($siteUrl)
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.RootWeb;
$contentTypeId = New-Object Microsoft.Sharepoint.SPContentTypeId($ctid)
$contentType = $web.ContentTypes[$contentTypeId]
$contentType.NewFormUrl = "_layouts/CustomNewDocset/CustomNewDocset.aspx"
$contentType.Update()
$web.Dispose()
$site.Dispose()

Now a custom new document set page has been created and the newFormUrl has been changed to use the new page. When you use the New Document drop down in a document library to create a new document set you should now get your custom page. 

Thanks for reading.

Quentin Christensen, Program Manager

Carlos David Argott Hernandez, Developer, Microsoft