Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用List.asmx原生Web服务和客户端对象模型向SharePoint列表添加新项目?_C#_Web Services_Sharepoint 2010_Sharepoint Clientobject - Fatal编程技术网

C# 如何使用List.asmx原生Web服务和客户端对象模型向SharePoint列表添加新项目?

C# 如何使用List.asmx原生Web服务和客户端对象模型向SharePoint列表添加新项目?,c#,web-services,sharepoint-2010,sharepoint-clientobject,C#,Web Services,Sharepoint 2010,Sharepoint Clientobject,我需要使用客户端对象模型和列表.asmxweb服务将项目添加到SharePoint列表中。 如何做到这一点 此外,我无法理解,当我们可以仅使用客户端对象模型直接向SharePoint列表添加项目时,为什么要使用list.asmxweb服务 有人能举个例子来解释我的疑问吗 关于何时使用CSOM和服务,有一些特定的场景 如果可以的话,您应该使用客户机对象模型(CSOM)——它不是 支持web服务的许多功能,但在 方法的数量,例如: 数据类型批处理命令(更有效地使用bandwith) 优化加载的数据

我需要使用客户端对象模型和列表.asmxweb服务将项目添加到SharePoint列表中。
如何做到这一点

此外,我无法理解,当我们可以仅使用客户端对象模型直接向SharePoint列表添加项目时,为什么要使用list.asmxweb服务

有人能举个例子来解释我的疑问吗

关于何时使用CSOM和服务,有一些特定的场景

如果可以的话,您应该使用客户机对象模型(CSOM)——它不是 支持web服务的许多功能,但在 方法的数量,例如:

数据类型批处理命令(更有效地使用bandwith) 优化加载的数据(更有效地利用带宽)更多 在编程方面类似于服务器端对象模型( 在大多数情况下,web服务只是大量未记录的XML 您需要解析)。。。所以,为了表现,你很可能会成功 更好地使用CSOM


谢谢你的快速回复,马杜尔。。。!但是我被要求同时使用CSOm和Lists.asmx。有可能吗?如果是这样的话,你能指导我如何使用lists.asmx吗?那没有意义。您可以使用CSOM或Lists.asmx。有几个关于如何执行此操作的示例:。这样做,然后在一个新问题中发布任何问题。是的……它工作得很好。非常感谢您的时间和帮助:)
using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
    class CreateListItem
    {
        static void Main()
        {   
            string siteUrl = "http://MyServer/sites/MySiteCollection";

            ClientContext clientContext = new ClientContext(siteUrl);
            SP.List oList = clientContext.Web.Lists.GetByTitle("Announcements");

            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem oListItem = oList.AddItem(itemCreateInfo);
            oListItem["Title"] = "My New Item!";
            oListItem["Body"] = "Hello World!";

            oListItem.Update();

            clientContext.ExecuteQuery(); 
        }
    }
}