SharePoint - 具有文件夹结构的自定义文档库

发布于 2024-10-04 13:07:55 字数 241 浏览 1 评论 0原文

我有一个带有内容类型的自定义文档库模板。这工作正常,但我想添加的唯一一件事是,当用户基于该模板实例化新文档库时,它已经具有预定义的文件夹结构。

我尝试在 schema.xml 中添加模块标签,但这似乎不起作用。

我知道可以使用 ListInstance 功能提供包含文件和文件夹的文档库,但在这种情况下这是不可能的。我希望预定义的文件夹结构是文档库模板的一部分。

这可能吗?

谢谢马丁

I have a custom document library template with content types. This works fine but the only thing that I would like to add is that when a user instantiates a new document library based on that template, that is has a predefined folder structure already in place.

I have tried adding Module tags in my schema.xml but this doesn't seem to work.

I know that it is possible to provision a document library with files and folders with a ListInstance feature but this is not possible in this case. I would like that the predefined folder structure is part of the document library template.

Is this possible?

Thanks

Maarten

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

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

发布评论

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

评论(2

聽兲甴掵 2024-10-11 13:07:55

如果您想使用文档库定义来实现此目的。我认为这是不可能实现的。您可以做的是借助列表/文档库模板。
1 按照您想要的方式创建自定义文档库。
2. 创建所需的文件夹结构。无需上传任何文件。
3,通过 Doclibray 设置将文档库另存为模板(确保将模板与存储在其中的内容一起存储)

If You want to achieve this using Document Library Definition. I don't think that would be achievable. What you can do is take help of list /document library templates.
1 Create a custom Doclibary the way you want.
2. create the desired folder structure. without uploading any documents.
3, Save the doc library as template by going to Doclibray settings ( make sure you store the template along with content stored into it)

阳光①夏 2024-10-11 13:07:55

另一种方法(我很快就会在博客上介绍)是伪造列表创建事件。我将带有自定义 aspx 页面的空视图定义添加到列表模板中。自定义页面只是在列表上执行一些自定义功能,删除初始化视图,然后重定向到普通视图。它有点混乱,只有通过 UI 创建列表时它才会起作用,但它确实有效。

这是一个非常简单的例子。您已经有了列表模板。在 schema.xml 文件中,向 Views 元素添加一个新视图,如下所示:

<Views>
  <!-- Below is a blank view used to kick of initialisation after list creation. -->
  <View DisplayName="Initialise" Type="HTML" DefaultView="TRUE"  WebPartZoneID="Main" SetupPath="pages\Scratch\init.aspx" Hidden="TRUE" Url="_init.aspx">
    <Toolbar Type="Standard" />
    <ViewHeader />
    <ViewBody />
    <ViewFooter />
    <ViewEmpty />
    <ViewFields />
    <ViewData />
    <Query />
  </View>
  <!-- standard views would be here -->
</Views>

您可以不使用其中的空元素。这是我在写博客之前要进一步测试的东西。但这将完成工作。重要的是:

  • 该视图是第一个视图,并且 DefaultView 设置为 TRUE。
  • SetupPath 设置为您将随解决方案配置的自定义页面。

对于自定义页面(在我的示例中为 init.aspx),我只是复制了 ...\12\TEMPLATE\Pages\viewpage.aspx 并更改了页面继承的内容。您可以使用内联代码来完成此操作,但我使用了代码隐藏程序集。因此该文件的第一行变为:

<%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="SharePointScratch.InitPage,SharePointScratch,Version=1.0.0.0,Culture=neutral,PublicKeyToken=xxxxxxxxxxxxxxxx" %>

然后是隐藏代码:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace SharePointScratch
{
    public class InitPage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SPList list = SPContext.Current.List;
            list.ParentWeb.AllowUnsafeUpdates = true;

            // Create you folder structure here...

            // Fix the views by deleting the initialisation view.
            SPView view = SPContext.Current.ViewContext.View;
            list.Views.Delete(view.ID);
            list.Update();

            list.ParentWeb.AllowUnsafeUpdates = false;

            // Redirect to the new default view.
            SPUtility.Redirect(list.DefaultViewUrl, SPRedirectFlags.Default, this.Context);
        }
    }
}

基本上,我们依靠 SharePoint 默认行为来显示创建后的列表的默认视图。在模式中插入自定义视图的唯一目的是触发一些自定义代码。自定义代码可以满足您的任何需求。之后,您可以通过从模板中删除特殊视图并重定向回该视图来进行清理。

Another method (which I must blog on soon) is to fake a list creation event. I add an empty view definition with a custom aspx page to the list template. The custom page simply executes some custom functionality on the list, deletes the initialisation view, then redirects to the normal view. It's a little messy, and it will only work if the list is created through the UI, but it works.

Here is a very quick example. You already have your list template. In the schema.xml file, add a new View to the Views element like so:

<Views>
  <!-- Below is a blank view used to kick of initialisation after list creation. -->
  <View DisplayName="Initialise" Type="HTML" DefaultView="TRUE"  WebPartZoneID="Main" SetupPath="pages\Scratch\init.aspx" Hidden="TRUE" Url="_init.aspx">
    <Toolbar Type="Standard" />
    <ViewHeader />
    <ViewBody />
    <ViewFooter />
    <ViewEmpty />
    <ViewFields />
    <ViewData />
    <Query />
  </View>
  <!-- standard views would be here -->
</Views>

You may be able to go without the empty elements in there. That was something I was going to test further before blogging on it. But this will get the job done. The important things are:

  • This view is the first view and DefaultView is set to TRUE.
  • The SetupPath is set to a custom page that you will provision with your solution.

For the custom page (init.aspx in my example), I just made a copy of ...\12\TEMPLATE\Pages\viewpage.aspx and changed what the page inherits from. You could do this with inline code, but I used a codebehind assembly. So first line of that file becomes:

<%@ Page language="C#" MasterPageFile="~masterurl/default.master" Inherits="SharePointScratch.InitPage,SharePointScratch,Version=1.0.0.0,Culture=neutral,PublicKeyToken=xxxxxxxxxxxxxxxx" %>

And then the codebehind:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace SharePointScratch
{
    public class InitPage : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            SPList list = SPContext.Current.List;
            list.ParentWeb.AllowUnsafeUpdates = true;

            // Create you folder structure here...

            // Fix the views by deleting the initialisation view.
            SPView view = SPContext.Current.ViewContext.View;
            list.Views.Delete(view.ID);
            list.Update();

            list.ParentWeb.AllowUnsafeUpdates = false;

            // Redirect to the new default view.
            SPUtility.Redirect(list.DefaultViewUrl, SPRedirectFlags.Default, this.Context);
        }
    }
}

Basically, we are relying on the SharePoint default behavior to display the default view of a list after creation. A custom view is inserted in the schema with the sole intention of firing off some custom code. The custom code does, well, whatever you want. After this, you clean up by deleting the special view from the template and redirecting back to the view.

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