将内容类型添加到所有文档库

发布于 2024-08-20 03:43:16 字数 835 浏览 5 评论 0原文

我们有数百个文档库,分布在 MOSS 2007 SharePoint 网站的各个网站集中。

问题是,除了“新文档”和“新文件夹”内容类型之外,我还想添加要显示的内容类型:“链接到文档”内容类型(0x01010A)。这种新的内容类型应该适用于所有现有的和新的文档库。


我尝试过的:

我认为我可以将以下内容添加到 节点内某处的 schema.xml 中:

<!-- Link to Document Content Type -->
<ContentTypeRef ID="0x01010A" />

C:\Program Files\Common Files\Microsoft Shared\Web 服务器扩展\12\TEMPLATE\FEATURES\Publishing\Pages\schema.xml

C:\Program Files\Common Files\Microsoft Shared \Web Server Extensions\12\TEMPLATE\FEATURES\DocumentLibrary\DocLib\schema.xml

这似乎已将内容类型添加到库中,但它没有显示在“新建”菜单下(仍然只显示“文档”和“文件夹”内容类型)。如果我设置“允许管理内容类型?”到“是”然后它就会出现。

tl;dr

问: 如何将“文档链接”内容类型添加到所有文档库并使其显示在“新建”菜单中?

We have hundreds of document libraries, spread all throughout various site collections in a MOSS 2007 SharePoint site.

The problem is, that I want to add Content Type to show up in addition to the "New Document" and "New Folder" content types: the "Link to a Document" content type (0x01010A). This new content type should should up for all existing and new document libraries.


What I've tried:

I thought that I would be able to add the following to a schema.xml somewhere inside the <ContentTypes></ContentTypes> node:

<!-- Link to Document Content Type -->
<ContentTypeRef ID="0x01010A" />

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\Publishing\Pages\schema.xml

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\DocumentLibrary\DocLib\schema.xml

This seems to have added the content type to the libraries OK, but it doesn't show up under the New menu (still just displays the "Document" and "Folder" content types). If I set "Allow management of content types?" to "Yes" then it shows up.

tl;dr

Q: How do I add the "Link to a Document" content type to all document libraries and have it show up in the New menu?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

江挽川 2024-08-27 03:43:16

如果您熟悉 SharePoint 对象模型,则可以以编程方式将内容类型添加到列表或库。因此,您可以编写一个功能接收器,甚至只是一个在服务器上运行的控制台应用程序,该应用程序将迭代站点内的所有列表并添加内容类型。

你的代码看起来像这样:

void AddContentTypeToList(string contentTypeId, SPSite site, SPList list)
{
    SPContentTypeId ctid = new SPContentTypeId(contentTypeId);
    SPContentType ct = site.RootWeb.ContentTypes[ctid];
    if (list.ContentTypes[ct.Name] == null)
    {
        list.ContentTypes.Add(ct);
        list.Update();
    }
}

If you're comfortable with the SharePoint object model, it's possible to add a content type to a list or library programmatically. So you could write a feature receiver or even just a console application to be run on the server that would iterate through all lists within a site and add the content type.

Your code would look something like:

void AddContentTypeToList(string contentTypeId, SPSite site, SPList list)
{
    SPContentTypeId ctid = new SPContentTypeId(contentTypeId);
    SPContentType ct = site.RootWeb.ContentTypes[ctid];
    if (list.ContentTypes[ct.Name] == null)
    {
        list.ContentTypes.Add(ct);
        list.Update();
    }
}
明月松间行 2024-08-27 03:43:16

管理新菜单中的按钮,使用 SPFolder。 UniqueContentTypeOrder 属性(SPList.RootFolder.UniqueContentTypeOrder 将带您到达那里)。

要将内容类型添加到新库...嗯...也许创建新的列表定义,添加一个停用文档库并激活自定义文档库功能的功能?如果您必须修改现有的生产 SharePoint 网站,可能需要花费太多精力。

顺便说一句,修改内置功能是不明智的(更新可以覆盖它们)。有一个用于此目的的 ContentTypeBinding 功能元素。然而,它只是将 ContentType 绑定到 1 个列表。

To manage buttons in new menu, use SPFolder.UniqueContentTypeOrder property (SPList.RootFolder.UniqueContentTypeOrder will get you there).

To add Content Type to new libraries... hmm... maybe create new List Definition, add a feature that deactivates document library and activates your custom document library feature? Probably too much effort if you have to modify existing, production SharePoint web's.

By the way it is not wise to modify built - in features (update's can overwrite them). There is a ContentTypeBinding feature element for this purpose. However it just binds ContentType to 1 list.

執念 2024-08-27 03:43:16

经过更多调查后,我发现通过更改 ..\12\TEMPLATE\FEATURES\DocumentLibrary\DocLib\schema.xml 我可以将链接到文档内容类型添加到所有新文档库。更改 schema.xml 然后执行 IISRESET 不会更改现有库。

为了做到这一点,我的 schema.xml 的开头看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="$Resources:shareddocuments_Title;" Direction="$Resources:Direction;" Url="Shared Documents" BaseType="1" EnableContentTypes="TRUE">
  <!-- Link to Document Content Type - Added EnableContentTypes="TRUE" -->
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x0101">
        <Folder TargetName="Forms/Document" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
      <!-- Link to Document Content Type -->
      <ContentTypeRef ID="0x01010A" />
    </ContentTypes>

由于这不会更改现有的文档库,因此我需要编写一个控制台应用程序,该应用程序使用其他两个答案中指定的代码来更新每个库。

After doing some more investigation, I found out that by changing ..\12\TEMPLATE\FEATURES\DocumentLibrary\DocLib\schema.xml I could add the Link to a Document content type to all NEW document libraries. Changing the schema.xml and then doing an IISRESET did not change existing libraries.

In order to do this, the beginning of my schema.xml looked something like this:

<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint" Title="$Resources:shareddocuments_Title;" Direction="$Resources:Direction;" Url="Shared Documents" BaseType="1" EnableContentTypes="TRUE">
  <!-- Link to Document Content Type - Added EnableContentTypes="TRUE" -->
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x0101">
        <Folder TargetName="Forms/Document" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
      <!-- Link to Document Content Type -->
      <ContentTypeRef ID="0x01010A" />
    </ContentTypes>

Since this didn't change existing document libraries, I will need to write a console application that uses the code specified in the other two answers to update each library.

梅窗月明清似水 2024-08-27 03:43:16

URL 字段需要添加到元素中的 Schema.XML 中。源代码可以在Template 目录下的源文件之一中找到(现在无法查找)。只需复制粘贴“URL”元素即可。

The URL field needs to be added to the Schema.XML in the element. The source can be found in one of the source files in the Template directory (can't look it up now). Just copy-paste the element for "URL".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文