尝试创建列表时“操作无效”

时间:2011-11-30 14:07:26

标签: sharepoint list sharepoint-2010

我想在Sharepoint中克隆一个列表。这是代码:

private static void CloneList(SPList sourceList, string targetListName)
{
    SPWeb web = sourceList.ParentWeb;
    web.AllowUnsafeUpdates = true;

    Guid targetListId;
    targetListId = web.Lists.Add(targetListName, sourceList.Description, sourceList.BaseTemplate);  
   // irrelevant stuff
}

在最后一个代码行(Lists.Add())上我收到错误

operation is not valid due to the current state of the object sharepoint 2010

知道如何解决这个问题? (使用elevatedPrivilegues运行代码无法解决问题)

1 个答案:

答案 0 :(得分:2)

试试这个......

targetListId = web.Lists.Add(targetListName, sourceList.Description, SPListTemplateType.CustomGrid)

Greats Hechler