【问题标题】:How to delete objects in Sharepoint with C#?如何使用 C# 删除 Sharepoint 中的对象?
【发布时间】:2022-09-25 21:07:14
【问题描述】:

我有一个由 SSIS 条件拆分生成的列表。 我尝试使用 C# 从列表中的每个项目中删除 sharepoint 站点 但是,我执行 deleteobject() ;和context.ExecuteQuery();它捕获以下错误:

[移动 SP SOQ [297]] 错误:ExecuteQuery SP Insert.Item 上的错误确实 不存在。

您选择的页面包含不存在的项目。它可能已被其他用户删除。

        //Authentification au site SP page prncipale
        string url = Variables.ListURLdelete;
        ClientContext context = new ClientContext(url);
        context.AuthenticationMode = ClientAuthenticationMode.Default;
        context.Credentials = new NetworkCredential(Variables.WebServiceServerUserName, Variables.WebServiceServerPassword);

        Web web = context.Web;
      
        List SOQList = context.Web.Lists.GetByTitle(\"SOQ\");
        var item = SOQList.AddItem(new ListItemCreationInformation());
        if (Row.SOQENDDate >= 10)
        {

            if (!Row.Assignment_IsNull)
            {
                item[\"SOQAssignmentCode\"] = Row.Assignment;
            }
            //if (!Row.AssignmentLabel_IsNull)
            //{
            //    item[\"SOQAssignmentStatus\"] = Row.AssignmentLabel;
            //}
            //if (!Row.SOQTitle_IsNull)
            //{
            //    item[\"Title\"] = Row.SOQTitle;
            //}
            //Insertion dans SP
            // https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee539976(v=office.14)
            try
            {
                Console.WriteLine(item);
                item.DeleteObject();
            }
            catch (Exception d)
            {
                ComponentMetaData.FireError(0, \"\", \"Error on Update Items SP Insert.\" + d.Message, \"\", 0, out vbool);
            }
            try
            {
                context.ExecuteQuery();
            }
            catch (Exception d)
            {
                ComponentMetaData.FireError(0, \"\", \"Error on ExecuteQuery SP Insert.\" + d.Message, \"\", 0, out vbool);
            }
        }

    }

可能是错误在列表 SOQList = context.Web.Lists.GetByTitle(\"SOQ\");?

    标签: c# sharepoint


    【解决方案1】:
    // Authentification au site SP page prncipale
            string url = Variables.Test;
            ClientContext context = new ClientContext(url);
            context.AuthenticationMode = ClientAuthenticationMode.Default;
            context.Credentials = new NetworkCredential(Variables.WebServiceServerUserName, Variables.WebServiceServerPassword);
    
            Web web = context.Web;
    
            List SOQList = context.Web.Lists.GetByTitle("SOQ");
    
            if (Row.SOQStartDate >= 10 & !Row.SPID_IsNull)
            {
                 This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
                 so that it grabs all list items, regardless of the folder they are in.
                CamlQuery query = CamlQuery.CreateAllItemsQuery();
                ListItemCollection items = SOQList.GetItems(query);
    
    
                context.Load(SOQList, list => list.ItemCount);
                context.ExecuteQuery();
    
                int startcount = SOQList.ItemCount;
                // delete du status
                ListItem listItem = SOQList.GetItemById(Row.SPID); -->OK
    
                try
                {
                    listItem.DeleteObject();
                    // SOQList.Update();
    
                }
                catch (Exception d)
                {
                    ComponentMetaData.FireError(0, "", "Error on Update Items SP Insert." + d.Message, "", 0, out vbool);
                }
                try
                {
                    context.ExecuteQuery();
    
                }
                catch (Exception d)
                {
                    ComponentMetaData.FireError(0, "", "Error on ExecuteQuery SP Update." + d.Message, "", 0, out vbool);
                }
                context.Load(SOQList, list => list.ItemCount);
                context.ExecuteQuery();
    
                int endcount = SOQList.ItemCount;
                Console.WriteLine("Start: {0}  End: {1}", startcount, endcount);
            }
    

    【讨论】:

      猜你喜欢
      • 2013-05-12
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多