SharePoint - custom document library with folder structure

I have my own document library template with content types. This works fine, but the only thing I would like to add is that when the user creates an instance of a new document library based on this template, it has a predefined folder structure already in place.

I tried adding module tags to my schema.xml, but this does not work.

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

Is it possible?

thank

Maarten

+3
source share
2 answers

Another way (which I should do in the blog in the near future) is to fake the list creation event. I am adding an empty view definition with a custom aspx page to the list template. The user page simply performs some user functions in the list, deletes the initialization view, and then redirects to the normal view. This is a bit dirty and it will only work if the list is created through the user interface, but it works.

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

<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 can pass without empty elements. That was what I was going to check on before I blog. But it will do its job. Important things:

  • , DefaultView - TRUE.
  • SetupPath ​​ , .

(init.aspx ) ... \12\TEMPLATE\Pages\viewpage.aspx , . , codebehind. , :

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

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

, SharePoint, . - . , , . , .

+2

, . , . , /. Doclibary , . 2. . - . 3 doc , Doclibray (, , )

+3

Source: https://habr.com/ru/post/1777080/


All Articles