4

I am new to CSOM and below is my first console application. the web is not recognising. Though all the dll in 15 hive are verified. Please help

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Client; 

namespace Microsoft.SDK.SharePointServices.Samples
{
    class DisplayWebTitle
    {
        static void Main()
        {
            ClientContext clientContext = new ClientContext("http://****");            
            Site oSite = clientContext.Site;             
            Web oWebsite = clientContext.Web; 
            clientContext.Load(oWebsite);          
            clientContext.ExecuteQuery();

        }
    }
}
SPuser
  • 51
  • 3
  • Copy & Paste the entire contents of your C# file, I reckon there's a namespace you don't need that's confusing it. – James Love Aug 20 '15 at 14:26
  • using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Client;

    namespace Microsoft.SDK.SharePointServices.Samples { class DisplayWebTitle { static void Main() { ClientContext clientContext = new ClientContext("http://****"); Site oSite = clientContext.Site; Web oWebsite = clientContext.Web; clientContext.Load(oWebsite); clientContext.ExecuteQuery();

    }
    

    } }

    – SPuser Aug 20 '15 at 14:51
  • If the error is Microsoft.Web, then i think it's not resolving web properly. Try explicitly declaring web as Microsoft.SharePoint.Client.Web – Akhoy Aug 20 '15 at 14:58
  • I dont see anything like using Microsoft.SharePoint.Client.web – SPuser Aug 20 '15 at 14:59
  • Not as a namespace, use Microsoft.SharePoint.Client.Web web = clientContext.Web – Akhoy Aug 20 '15 at 15:02
  • Oh yes thats solves the problem... but do i need to use the full extension everytime? – SPuser Aug 20 '15 at 15:05
  • It's causing a conflict with class names being the same in two different assemblies. See if this helps : http://stackoverflow.com/questions/3018419/class-with-same-name-in-two-assemblies-intentionally – Akhoy Aug 20 '15 at 15:18
  • Or, since you use client code, remove this using: using Microsoft.SharePoint statement that is for server side code – Robert Lindgren Aug 20 '15 at 15:22
  • Right @RobertLindgren, nice find. Didn't see that there! :) – Akhoy Aug 20 '15 at 16:26

1 Answers1

1

Since you use client side code you should not add the Microsoft.SharePoint (since that one is for the server object model) to the usage statements, so your file should look like this:

using System;
using Microsoft.SharePoint.Client; 

namespace Microsoft.SDK.SharePointServices.Samples
{
    class DisplayWebTitle
    {
        static void Main()
        {
            ClientContext clientContext = new ClientContext("http://****");            
            Site oSite = clientContext.Site;             
            Web oWebsite = clientContext.Web; 
            clientContext.Load(oWebsite);          
            clientContext.ExecuteQuery();

        }
    }
}
Robert Lindgren
  • 24,520
  • 12
  • 53
  • 79