问题
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