Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.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#控制台应用程序验证sharepoint用户登录时出错_C#_Sharepoint_Sharepoint 2010_Sharepoint 2013 - Fatal编程技术网

通过c#控制台应用程序验证sharepoint用户登录时出错

通过c#控制台应用程序验证sharepoint用户登录时出错,c#,sharepoint,sharepoint-2010,sharepoint-2013,C#,Sharepoint,Sharepoint 2010,Sharepoint 2013,我在通过c#控制台应用程序验证共享点的用户凭据时出错 我正在尝试下面的代码进行身份验证 using (ClientContext ctx = new ClientContext("https://sharepointurl")) { ctx.Credentials = new NetworkCredential(@"username", "password", "domain");

我在通过c#控制台应用程序验证共享点的用户凭据时出错

我正在尝试下面的代码进行身份验证

     using (ClientContext ctx = new ClientContext("https://sharepointurl"))
                {
                    ctx.Credentials = new NetworkCredential(@"username", "password", "domain");
                    // Get the SharePoint web  
                    Web web = ctx.Web;
                    // Load the Web properties  
                    ctx.Load(web); 

}
但是在第二行
ctx.Credentials
中,我得到了一个错误-

ServerVersion='ctx.ServerVersion'引发了类型为的异常 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException'

我已经添加了
dll
referenceof
Microsoft.SharePoint
Microsoft.SharePoint.RunTime
版本
16.0.0.0
,并且还通过
15.0.0.0


知道问题出在哪里吗?

在用户名之前删除@。并且不要忘记加载()后的ctx.ExecuteQuery()


您应该(正如@vinayak hegde所提到的)添加Microsoft.SharePoint.Client/.Client.Runtime DLL。Microsoft.SharePoint.dll用于服务器。

在ClientContext中运行,为什么需要Microsoft.SharePoint和Microsoft.SharePoint.RunTime,请参考Microsoft.SharePoint。Client@vinayakhegde是,它的Microsoft.SharePoint.Client继承自Microsoft.SharePoint