当我尝试使用Visual Studio aspx页面在SharePoint 2016中创建新的文档集时,我得到了异常。 例外:对象引用未设置为对象的实例。
请帮忙。
网站示例网址:http://dev-office.my-site.local
列表(库)名称:TestSolution
库已存在,文档集可用,并在此库中手动创建。 ApplicationPage1.aspx用作默认表单,为当前库创建新的DocumentSet。
Сode下面:
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;
}
}
}
}
答案 0 :(得分:0)
答案:问题出在语言环境中,您必须在命名时使用西里尔语或拉丁语。