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的备份

posted @ 2010-09-06 17:04  绿森林  阅读(280)  评论(0编辑  收藏  举报