找不到SPSite名称空间

OPK*_*OPK 3 c# sharepoint sharepoint-clientobject

我无法找到名称空间 SPSite

到目前为止我已导入这些:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Microsoft.SharePoint;
using System.Collections;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint;
using System.Data.SqlClient;
using SP = Microsoft.SharePoint.Client;
using System.Data;


namespace GrandPermission
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSite oSPSite = new SPSite("http://spdevserver:1002/");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

而且SPSite还有其下红线. 在此输入图像描述 在此输入图像描述

Vad*_*hev 9

由于SPSite类是服务器端对象模型API 的一部分,因此会发生此错误:

服务器端对象模型 API 只能在安装了SharePoint Server/Foundation的计算机上使用.

由于您使用的是客户端对象模型API(项目中引用的程序集Microsoft.SharePoint.Client.dll是SharePoint Server 2013客户端组件SDK的一部分),我建议使用此API.

所以,行:

SPSite oSPSite = new SPSite("http://spdevserver:1002/");  //SSOM
Run Code Online (Sandbox Code Playgroud)

可以替换为:

using(var ctx = new ClientContext("http://spdevserver:1002/"))
{
    var site = ctx.Site;
    //...
}
Run Code Online (Sandbox Code Playgroud)

参考