4

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

OPK
  • 4,120
  • 6
  • 36
  • 66
  • Spsite is part of the Microsoft.SharePoint namespace. You've added a reference to it twice at the top, not sure if that would cause a problem. What happens when you try `Microsoft.SharePoint.SPSite oSPSite = new Microsoft.SharePoint.SPSite("https://spdevserver:10002/");`? – Robbert Apr 14 '15 at 17:23
  • @Robbert I tried and still has red line saying missing reference. – OPK Apr 14 '15 at 17:26
  • Did you actually add a reference to Microsoft.SharePoint in the references section of Visual Studio? Adding `using Microsoft.SharePoint;` isn't good enough. – Robbert Apr 14 '15 at 17:27
  • @Robbert I added another screen shot showing all the references I have added, could you have a look? – OPK Apr 14 '15 at 17:30

3 Answers3

12

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

Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
1

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.

Robbert
  • 6,481
  • 5
  • 35
  • 61
  • I could not find the `Microsoft.SharePoint.dll`. I looked all over but `Microsoft.SharePoint.dll` was not there. If you can guide me to the right location I will accept the answer. – OPK Apr 14 '15 at 17:41
  • Are you developing on a SharePoint server? What version of .Net are you using? 32bit or 64bit? – Robbert Apr 14 '15 at 17:42
  • Developing on SharePoint server? I think this might be the problem, but I do not know what you mean by "develop on SharePoint server". I am on Windows 7 desktop using visual studio 2013. `.net` 4.0, 64bit – OPK Apr 14 '15 at 17:46
  • would you happen to know the `Microsoft.SharePoint.dll` file location after the SharePoint server is installed? – OPK Apr 14 '15 at 18:14
  • Should be in the bin folder. – Robbert Apr 14 '15 at 18:21
1

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
techspider
  • 3,370
  • 13
  • 37
  • 61