Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find the SPSite name space

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. enter image description hereenter image description here

like image 927
OPK Avatar asked Dec 12 '22 00:12

OPK


2 Answers

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
like image 77
Vadim Gremyachev Avatar answered Dec 25 '22 18:12

Vadim Gremyachev


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.

like image 21
Robbert Avatar answered Dec 25 '22 19:12

Robbert