0

当我尝试使用 Visual Studio aspx 页面在 SharePoint 2016 中创建新文档集时,出现异常。例外:对象引用未设置为对象的实例。

请帮忙。

站点示例网址:http://dev-office.my-site.local

列表(库)名称:TestSolution

库已经存在,文档集可用,并且是在此库中手动创建的。ApplicationPage1.aspx 用作为当前库创建新 DocumentSet 的默认表单。

下面的代码:

ApplicationPage1.aspx 有四个控件:两个TextBox(名称、描述)、一个Button 和一个用于显示错误的标签。在 OnClick action="createDocSetButton_Click" 按钮上,它应该创建一个新的文档集。

    <%@ 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 它有一个简单的方法,绑定到一个按钮并创建一个文档集。

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;
        }            

    }

}
}
4

1 回答 1

0

答:问题出在语言环境中,您必须在命名时仅使用西里尔文或拉丁文。

于 2018-05-28T09:07:49.657 回答