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.
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;
//...
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With