无法使用Sharepoint客户端对象模型连接到sharepoint站点

时间:2013-09-19 18:55:25

标签: sharepoint

我正在尝试编写一个控制台应用程序来连接到我们的某个sharepoint应用程序站点。我正在运行一个基本示例来确保连接。程序因以下错误而失败: 远程服务器返回错误:(500)内部服务器错误。

状态:System.Net.WebExceptionStatus.ProtocolError

我无权访问IIS服务器来检查日志。我的代码如下:

        string siteUrl = "http://spsiteurl/";


        ClientContext clientContext = new ClientContext(siteUrl);
        clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
        clientContext.Credentials = new NetworkCredential("...", "...", "...");

        Web oWebsite = clientContext.Web;

        clientContext.Load(oWebsite,
            w => w.Title);

        clientContext.ExecuteQuery();

        Console.WriteLine(oWebsite.Title);

我可能出错的方向?

1 个答案:

答案 0 :(得分:1)

尝试以下代码

    ClientContext context = new ClientContext("https://test.com/");
    System.Net.ServicePointManager.ServerCertificateValidationCallback =
        ((sender, certificate, chain, sslPolicyErrors) => true);

    string strUserName = @"abc";
    string strPassword = "pwd";
    var credentials = new NetworkCredential(strUserName, strPassword);
    Web web = context.Web;
    context.Load(web, w => w.Title);
    context.Credentials = credentials;
    context.ExecuteQuery();


    // Now, the web's properties are available and we could display 
    // web properties, such as title. 
    System.Console.WriteLine("Web Title");
    System.Console.WriteLine(web.Title);

它可以在控制台中正常工作

相关问题