C# 缺少 using 指令或程序集引用 (ClientContext)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8917043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 05:09:43  来源:igfitidea点击:

Missing a using directive or an assembly reference (ClientContext)

c#visual-studio-2010sharepoint

提问by MXV

I'm trying to test this code snippet but I get the "Missing a using directive or an assembly reference" error on "ClientContext oContext = new ClientContext(siteUrl);" I'm copying and pasting directly from the Microsoft site so I'm not sure what am I missing...

我正在尝试测试此代码片段,但在“ClientContext oContext = new ClientContext(siteUrl);”上出现“缺少 using 指令或程序集引用”错误。我直接从微软网站复制和粘贴,所以我不确定我错过了什么......

using System;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointServices.Samples
{
    class BreakSecurityInheritance
    {
        static void Main()
        {
            string siteUrl = "http://MyServer/sites/MySiteCollection";
            ClientContext oContext = new ClientContext(siteUrl);
            SP.List oList = oContext.Web.Lists.GetByTitle("Announcements");

            oList.BreakRoleInheritance(true, false);

           oContext.ExecuteQuery();
        }
    }
}

采纳答案by John Patrick Dandison

As said earlier, you need a reference to the SharePoint client object model. Luckily, you can get those from Microsoft as part of the SP Client OM redistributable without having to install a full local SharePoint server.

如前所述,您需要引用 SharePoint 客户端对象模型。幸运的是,您可以从 Microsoft 获取这些作为 SP Client OM 可再发行组件的一部分,而无需安装完整的本地 SharePoint 服务器。

http://www.microsoft.com/download/en/details.aspx?id=21786

http://www.microsoft.com/download/en/details.aspx?id=21786

回答by Frédéric Hamidi

First you're bringing the members of Microsoft.SharePoint.Clientinto the global scope, but right afterwards you're remapping that namespace to the SPalias.

首先,您将 的成员Microsoft.SharePoint.Client带入全局范围,但随后您将该命名空间重新映射到SP别名。

That means you should qualify its members with the alias:

这意味着您应该使用别名来限定其成员:

SP.ClientContext oContext = new SP.ClientContext(siteUrl);

Or remove the aliasing and use plain List, but I suppose the alias is there to prevent conflicts with List<T>in the first place.

或者删除别名并使用 plain List,但我认为别名首先是为了防止与冲突List<T>

回答by MethodMan

I don't see any Query and if this is taken from the site then you are missing a Query.. otherwise you have nothing to Execute not to mention you need to do some Name resolution probably within your code.. Here is the Link to the example he's trying to imulateHow To use SharePoint with C#

我看不出有任何查询,如果这是从网站,那么你缺少一个查询中获取..否则,你有什么执行何况你需要做的也许在你的代码中的一些名称解析..这里是链接到他试图模拟如何在 C# 中使用 SharePoint的示例

Mark have you actually gone to the project , right clicked on reference and select add then navigate to where the Microsoft.SharePoint.Client dll is.. are you getting a yellow icon in the project properties when you build the project..??

标记您是否真的进入了项目,右键单击引用并选择添加,然后导航到 Microsoft.SharePoint.Client dll 所在的位置.. 构建项目时,项目属性中是否出现黄色图标..??