如何:新建文档集窗体
上次修改时间: 2015年3月9日
适用范围: SharePoint Server 2010
Microsoft SharePoint Server 2010 包含一个用于创建文档集的新窗体。该窗体位于 _layouts 文件夹中;存在一个窗体供所有文档集内容类型使用。利用自定义窗体,您可以自动填写元数据或包含条件格式,以便根据用户所选择的选项仅显示某些字段。
文档集内容类型包含一个名为 NewFormUrl 的属性。通过更改此属性,您可为每个文档集内容类型指定一个新窗体。在更改此属性之前,请新建一个 .aspx 窗体并将其存储在 _layouts 文件夹或 _layouts 中的某个文件夹。如果您将该窗体存储在某个文件夹内部,您必须添加包含有关文档集程序集的信息的 web.config 文件。该文档集对象模型需要 web.config 文件来创建文档集。
CustomNewDocSet.aspx
创建文档集窗体
创建一个 .aspx 窗体并将其存储在 _layouts 文件夹或 _layouts 中的某个文件夹。
CustomNewDocSet.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CustomNewDocset.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://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>
代码隐藏页
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; } }
更新文档集内容类型 URL 以使用自定义的新文档集页。
提示
您可以使用 ChangeNewDocSetPage.ps1 来更新文档集内容类型 URL。该示例脚本传入指向包含要更改的文档集内容类型的网站的 URL。ctid 表示要更改的内容类型的适当内容类型 ID。该脚本将 NewFormUrl 属性更新为使用自定义的新文档集页而不是默认页,并且使用如下所示的参数。该脚本创建一个自定义的新文档集页并将 newFormUrl 更新为使用该新页。当使用文档库中的"新建文档"下拉列表创建新的文档集时,自定义页应显示在该列表上。
表 1. ChangeNewDocSetPage.ps1 对象引用
对象引用
说明
$contentType.NewFormUrl
相对于 _layouts 文件夹的包含自定义的新文档集窗体的位置。
$ctid
要修改的文档集的内容类型 ID。
$siteurl
指定自定义文档集内容类型的 URL。
ChangeNewDocSetPage.ps1
$siteUrl = "http://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()
创建一个 web.config 文件(新文档集内容类型页所必需的),并将该文件置于包含自定义的新文档集 .aspx 页的文件夹中。
备注
如果您将新文档集内容类型页添加到了 _layouts 的根目录中,则可以跳过此步骤。您可以根据需要添加对其他程序集的引用。
Web.Config<?xml version="1.0"?> <!-- Note: As an alternative to manually editing this file, you can use the Web admin tool with the ASP.NET Configuration option to configure settings for your application. 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>