MOSS复制一个list的结构

转自jianyi的博客

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

 

可以用于list的备份

你可能感兴趣的:(list)