如果您可以使用自定义代码,则可以覆盖FeatureActivated event receiver
该功能以创建列表和文件夹。
您将需要创建另一个功能以在配置文件的功能之前运行,并使文件配置功能依赖于第一个功能,以确保列表可用。
或者,您可以通过 xml 添加列表定义和实例。我个人尽可能避免这条路线,但您可以在MSDN - Creating List Definitions with Custom List Columns for SharePoint Server 2007中找到相关指南
通过代码添加列表的示例(警告 - 我没有 2007 年可供测试,但这确实适用于 2010 年,我认为我没有使用任何 2010 年特定代码)
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb web = properties.Feature.Parent as SPWeb; // Assuming web scoped feature
SPList customPagesList;
bool listExists = true;
//Check to see if the list exists, this method sucks but 2007 doesn't have web.TryGetList()
try
{
customPagesList = web.GetList("/CustomPages"); // server relative url of the list
}
catch (FileNotFoundException e)
{
listExists = false;
}
if (!listExists)
{
// Create list and record returned guid
Guid customPagesListGuid = web.Lists.Add("CustomPages",
"Library to store web pages used in the site", SPListTemplateType.DocumentLibrary);
//Get list from stored guid
customPagesList = web.Lists[customPagesListGuid];
// Set list properties and add required content types
customPagesList.Title = "CustomPages";
customPagesList.OnQuickLaunch = false; // Set to true to display on the quick launch
customPagesList.ContentTypesEnabled = true;
customPagesList.NoCrawl = true; // Set to false if you want pages indexed by search
customPagesList.EnableFolderCreation = true;
customPagesList.EnableSyndication = false; // Turn off rss
SPContentType webPartPageCT = web.AvailableContentTypes[SPBuiltInContentTypeId.WebPartPage];
SPContentType basicPageCT = web.AvailableContentTypes[SPBuiltInContentTypeId.BasicPage];
customPagesList.ContentTypes.Add(webPartPageCT);
customPagesList.ContentTypes.Add(basicPageCT);
// Remove the default content type added on list creation if it is not needed
DeleteContentType(customPagesList.ContentTypes, "Document");
// Commit changes
customPagesList.Update();
//Get library from stored guid
SPDocumentLibrary customPagesLibrary = (SPDocumentLibrary)web.Lists[customPagesListGuid];
customPagesLibrary.Folders.Add("/Lists/CustomPages/yyy", SPFileSystemObjectType.Folder);
string rootFolderUrl = customPagesLibrary.RootFolder.ServerRelativeUrl;
SPListItem newFolder = customPagesLibrary.Folders.Add(rootFolderUrl, SPFileSystemObjectType.Folder, "yyy");
newFolder.Update();
}
}
private void DeleteContentType(SPContentTypeCollection ctCollection, string ctName)
{
foreach (SPContentType ct in ctCollection)
{
if (ct.Name.Equals(ctName))
{
ct.Delete();
}
}
}