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>
<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>
</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;
SPView view = SPContext.Current.ViewContext.View;
list.Views.Delete(view.ID);
list.Update();
list.ParentWeb.AllowUnsafeUpdates = false;
SPUtility.Redirect(list.DefaultViewUrl, SPRedirectFlags.Default, this.Context);
}
}
}
, SharePoint, . - . , , . , .