cannot find the SPSite name space

半城伤御伤魂 提交于 2019-12-10 21:32:13

问题


I am unable to find the name space for the SPSite

I have imported these so far:

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/");
        }
    }
}

And SPSite still has red line under it.


回答1:


This error occurs since SPSite class is a part of Server Side Object Model API:

Server Side Object Model API could be utilized only on machine where SharePoint Server/Foundation is installed.

Since you are using Client Object Model API (referenced assembly in your project Microsoft.SharePoint.Client.dll is a part of SharePoint Server 2013 Client Components SDK) i would recommend to utilize this API.

So, the line:

SPSite oSPSite = new SPSite("http://spdevserver:1002/");  //SSOM

could be replaced with:

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

References

  • Choose the right API set in SharePoint 2013



回答2:


Based on your screenshot, you are missing a reference to Microsoft.SharePoint in your project's references. You only have a reference to the client dll.

If you're not finding it, make sure you're either developing on a SharePoint server, i.e. SharePoint is installed, or have a copy of the dll on your machine. I've seen forum posts where someone copied the SharePoint dll from a SharePoint server to a local non-SharePoint development machine. However, I've never gotten that to work. I've always installed SharePoint on a development server and ran Visual Studio from it.




回答3:


You need to add the assembly Microsoft.SharePoint.dll into your references in order to use it. You can find this DLL on the SharePoint server that you're working with:

On SharePoint 2013 it lives at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI

And on SharePoint 2010 it can be found at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI


来源:https://stackoverflow.com/questions/29633604/cannot-find-the-spsite-name-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!