Reputation: 11
I have write a code that contains SPSite and I got this error CS0246: The type or namespace name 'SPSite' could not be found (are you missing a using directive or an assembly reference?)
I have tried downloading Microsoft.SharePoint from the nuget site here https://www.nuget.org/packages/Microsoft.SharePoint.dll/ and then I have put the package in the right folder and still I have the same error
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using System.Net;
using System.Configuration;
using System.Collections.Specialized;
using System.Runtime;
using Microsoft.SharePoint;
using System.Reflection;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;
protected void getList()
{
string strUrl = " SharePoint SITE ";
using (SPSite oSite = new SPSite(strUrl))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList list = oWeb.Lists["Workplan"];
foreach (SPField field in list.Fields)
{
Console.WriteLine(field.Title);
}
}
}
}
after adding the package that I download in the right place I expected for the error to fade away still it's there. Help please!
Upvotes: 0
Views: 1190
Reputation: 4562
Install the nuget package, its the best way to use it. You can install with Package Manager UI (Visual Studio) or Package Manager Console (Visual Studio) see hear.
Note 1: SPSite
, SPWeb
, SPList
and SPField
are classes in namespace Microsoft.SharePoint
.
Note 2: you have in your code: using Microsoft.SharePoint;
and using Microsoft.SharePoint.Client;
, Microsoft.SharePoint
and Microsoft.SharePoint.Client
are two different nuget packages.
Yue
Upvotes: 0
Reputation: 11
For those who had the same problem as me. I found a solution that made the error disappear. Manage NuGet Packages
Click Manage NuGet Packages, and then in the browsing area tape 'Microsoft.SharePoint.dll' when you do that you would want to choose the right version of your NuGet Package in a way that it would be compatible with you .Net Framework Then Click install. Right after when you go back to the code, you will see the error went away. For more clearity hit me up in the comment.
Upvotes: -1