PETR
PETR

Reputation: 1

Exception on programmatically create new DocumentSet [SharePoint]

When I try create create a new Document Set in SharePoint 2016 by using Visual Studio aspx page, I get exception. Exception: Object reference not set to an instance of an object.

Please help.

Site example url: http://dev-office.my-site.local

List(Library) name: TestSolution

The Library already exists, Document Set is available, and is created manually in this library. ApplicationPage1.aspx is used as the default form to create a new DocumentSet for the current library.

Сode below:

ApplicationPage1.aspx There are four controls: two TextBox (name, description), one Button and label for displaying errors. On the OnClick action="createDocSetButton_Click" button, which should create a new Document set.

    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ApplicationPage1.aspx.cs" Inherits="SharePointProject17.Layouts.SharePointProject17.ApplicationPage1" DynamicMasterPageFile="~masterurl/default.master" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">

    <p>
        Name: <asp:TextBox ID="nameTextbox" runat="server"></asp:TextBox>
    </p>
    <p>
        Description: <asp:TextBox ID="descriptionTextbox" runat="server"></asp:TextBox>
    </p>

    <asp:Button ID="createDocSetButton" OnClick="createDocSetButton_Click" runat="server" Text="Create Document Set" />
    <asp:Label ID="resultLabel" runat="server" Text=""></asp:Label>  

</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">

</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >

</asp:Content>

ApplicationPage1.aspx.cs It has a simple method that is bound to a button and creates a Document Set.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Office.DocumentManagement.DocumentSets;
using System.IO;
using System.ComponentModel;
using System.Web;
using Microsoft.SharePoint.Client;


namespace SharePointProject17.Layouts.SharePointProject17
{
    public partial class ApplicationPage1 : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            nameTextbox.Focus();
    }

    protected void createDocSetButton_Click(object sender, EventArgs e)
    {
        //Get the Shared Documents document library
        SPWeb currentWeb = SPContext.Current.Web;
        SPList sharedDocsLib = currentWeb.Lists["TestSolution"];
        //You can use a hashtable to populate properties of the document set
        Hashtable docsetProperties = new Hashtable();
        docsetProperties.Add("Name", nameTextbox.Text);
        docsetProperties.Add("Description", descriptionTextbox.Text);
        //Create the document set
        try
        {
            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 = "Error: " + ex.Message;
        }            

    }

}
}

Upvotes: 0

Views: 433

Answers (1)

PETR
PETR

Reputation: 1

Answer: the problem is in the locale, you must use either only Cyrillic or Latin in naming.

Upvotes: 0

Related Questions