提供了无效的参数“当我尝试使用SharePoint客户端对象模型和.NET应用程序在线连接sharepoint时出现错误 [英] An invalid argument was supplied" error when I try to connect sharepoint online using SharePoint Client Object Model with .NET application

查看:74
本文介绍了提供了无效的参数“当我尝试使用SharePoint客户端对象模型和.NET应用程序在线连接sharepoint时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过c#.net代码在线连接SharePoint(办公365云基础).我正在使用"Microsoft.SharepointOnline.CSOM"; NuGet软件包版本V16.1.7414.1200和应用程序.net框架4.5.2. 我已经在Google上尝试了所有不同类型的代码.没什么对我有用.

I am trying to connect SharePoint online (office 365 cloud base) through c#.net code.I am using "Microsoft.SharepointOnline.CSOM" NuGet package version V16.1.7414.1200 and application .net framework 4.5.2. I already tried all different type of code by looking on google. nothing is working for me.

在这里,我尝试了所有示例代码.

示例代码1

使用 ( ClientContext clientContext = ClientContext

using (ClientContext clientContext = new ClientContext("https://xxx.com"))

{

var psd = 密码"

                var psd = "password".ToCharArray();

SecureString SecureString

                SecureString secureString = new SecureString();

foreach ( char in

                foreach (char c in psd) secureString.AppendChar(c);

//psd.ToList().ForEach(secureString.AppendChar);

                //psd.ToList().ForEach(secureString.AppendChar);

 

clientContext.Credentials = SharePointOnlineCredentials 用户名"

                clientContext.Credentials = new SharePointOnlineCredentials("username", secureString);

            //Web oWeb = clientContext.Web;

               // Web oWeb = clientContext.Web;

            列表 标题" );

               List oList = clientContext.Web.Lists.GetByTitle("Title");

 

CamlQuery CamlQuery

                CamlQuery camlQuery = new CamlQuery();

camlQuery.ViewXml = < View>< RowLimit> 100</RowLimit></View>" ;

                camlQuery.ViewXml = "<View><RowLimit>100</RowLimit></View>";

 

ListItemCollection

                ListItemCollection collListItem = oList.GetItems(camlQuery);

 

clientContext.Load(collListItem,

项目=> items.Include(

           &bb ;    item => item.Id,

            ;    item => item.DisplayName,

            ;    item => item.HasUniqueRoleAssignments));

 

clientContext.ExecuteQuery();

 

foreach ( ListItem in

                foreach (ListItem oListItem in collListItem)

{

            ;    控制台 @" ID: {0} {1} {2}

                    Console.WriteLine(@"ID: {0} \nDisplay name: {1} \nUnique role assignments: {2}",

            ;    oListItem.Id,oListItem.DisplayName,oListItem.HasUniqueRoleAssignments);

}

          ; }

示例代码2

使用 ( ClientContext spcontext = ClientContext

using (ClientContext spcontext = new ClientContext(siteurl))

{

spcontext.AuthenticationMode = ClientAuthenticationMode

                spcontext.AuthenticationMode = ClientAuthenticationMode.FormsAuthentication;

spcontext.FormsAuthenticationLoginInfo = FormsAuthenticationLoginInfo 用户名" 密码"

                spcontext.FormsAuthenticationLoginInfo = new FormsAuthenticationLoginInfo("username", "password");

spcontext.Load(spcontext.Web,w => w.Title,w => w.ServerRelativeUrl,w => w.Lists);

尝试

                try

{

            ;     spcontext.ExecuteQuery();

           &bb ;    控制台

                    Console.WriteLine(spcontext.Web.ServerRelativeUrl);

}

捕获 ( 异常

                catch (Exception ex)

{

 

            ;    //throw;

                    //throw;

}

 

 

          ; }

我在所有示例代码上始终都遇到错误.

I am getting the error all the times on all sample codes.

仅供参考-我的计算机上没有代理设置

创建在'system.net/defaultProxy'配置部分中指定的Web代理时出错. "}

堆栈跟踪-

在System.Net.SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily addressFamily,SocketType套接字类型,ProtocolType协议类型,布尔值自动重置,指示布尔值的

at System.Net.SafeCloseSocketAndEvent.CreateWSASocketWithEvent(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType, Boolean autoReset, Boolean signaled)

  在System.Net.NetworkAddressChangePolled..ctor()

   at System.Net.NetworkAddressChangePolled..ctor()

  在System.Net.AutoWebProxyScriptEngine.AutoDetector.Initialize()

   at System.Net.AutoWebProxyScriptEngine.AutoDetector.Initialize()

  在System.Net.AutoWebProxyScriptEngine.AutoDetector.get_CurrentAutoDetector()

   at System.Net.AutoWebProxyScriptEngine.AutoDetector.get_CurrentAutoDetector()

  在System.Net.AutoWebProxyScriptEngine..ctor(WebProxy代理,布尔值useRegistry)

   at System.Net.AutoWebProxyScriptEngine..ctor(WebProxy proxy, Boolean useRegistry)

  在System.Net.WebProxy.UnsafeUpdateFromRegistry()

   at System.Net.WebProxy.UnsafeUpdateFromRegistry()

  在System.Net.WebProxy..ctor(布尔enableAutoproxy)

   at System.Net.WebProxy..ctor(Boolean enableAutoproxy)

  在System.Net.Configuration.DefaultProxySectionInternal..ctor(DefaultProxySection部分)中

   at System.Net.Configuration.DefaultProxySectionInternal..ctor(DefaultProxySection section)

  在System.Net.Configuration.DefaultProxySectionInternal.GetSection()

   at System.Net.Configuration.DefaultProxySectionInternal.GetSection()

因此,我还更改了我的app.config文件中的默认代理设置.

< system.net>

    < defaultProxy enabled ="false"; useDefaultCredentials ="false">

      < proxy/>

      < bypasslist>

       <添加地址="[a-z] + \.[a-z] + \.[a-z] +". />

      </bypasslist>

      < module/>

    </defaultProxy>

  </system.net>

但是在更改了上面的配置设置之后,我得到了以下错误提示.

基础连接已关闭:无法连接到远程服务器.

内部异常一直存在,如下所示.

{提供了无效的参数"}}-2147467259

{"An invalid argument was supplied"} -2147467259

代码参考来自以下URL

https://docs.microsoft.com/zh-cn/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code

https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code

推荐答案

这是代理服务器的问题,您的网络正在使用代理服务器.

It is the problem of proxy server and your network is using proxy server.

我们需要如下设置代理服务器的IP和端口号.

We need to set the IP and Port number of proxy server as below.

<system.net>
  <defaultProxy>
     <proxy proxyaddress="http://[Proxy IP Address]:[Proxy Port Number]" bypassonlocal="True" />
  </defaultProxy>
</system.net> 

此外,关于如何进行身份验证以访问CSOM中的SharePoint Online,以下是一个演示.

In addition, About how to do authentication to access SharePoint online in CSOM,  here is a demo as below.

        public static void setOnlineCredential(ClientContext clientContext,string userName,string password)
        {
            //set the user name and password
            SecureString secureString = new SecureString();
            foreach (char c in password.ToCharArray())
            {
                secureString.AppendChar(c);
            }
            clientContext.Credentials = new SharePointOnlineCredentials(userName, secureString);           
        }

最诚挚的问候,

李刘


这篇关于提供了无效的参数“当我尝试使用SharePoint客户端对象模型和.NET应用程序在线连接sharepoint时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆