//templateList是作为模板的列表或文档库
SPList EnsureArchiveList( SPList templateList)
{
SPWeb web = templateList.ParentWeb;
SPList list = templateList;
SPList archiveList = null;
string archiveListTitle = list.Title + "(Archive)";
try
{
archiveList = web.Lists[archiveListTitle];
}
catch { }
if (archiveList == null)
{
web.AllowUnsafeUpdates = true;
string url = "Archive/" + list.RootFolder.Url;
Guid listId = web.Lists.Add(list.Title + "(Archive)", "List for archive.", url , list.TemplateFeatureId.ToString(), (int)list.BaseTemplate, "");
archiveList = web.Lists[listId];
foreach (SPField f in list.Fields)
{
if (archiveList.Fields.ContainsField(f.InternalName) == false)
{
archiveList.Fields.Add(f);
}
}
}
return archiveList;
}