0

我编写了一个包含 SPSite 的代码,但出现此错误 CS0246: The type or namespace name 'SPSite' could not be found(您是否缺少 using 指令或程序集引用?)

我已经尝试从这里的 nuget 站点https://www.nuget.org/packages/Microsoft.SharePoint.dll/下载 Microsoft.SharePoint ,然后我将包放在正确的文件夹中,但我仍然有同样的错误

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);
               }
           }
       }
   }

在正确的位置添加我下载的包后,我预计错误会消失,但它仍然存在。请帮忙!

4

2 回答 2

0

安装 nuget 包,这是使用它的最佳方式。您可以使用包管理器 UI (Visual Studio) 或包管理器控制台 (Visual Studio) 进行安装,请参阅

注 1:SPSiteSPWeb和是命名空间中的SPList类。SPFieldMicrosoft.SharePoint

注意 2:您的代码中有:using Microsoft.SharePoint;using Microsoft.SharePoint.Client;,Microsoft.SharePointMicrosoft.SharePoint.Client是两个不同的 nuget 包。

于 2019-05-14T11:48:18.090 回答
-1

对于那些和我有同样问题的人。我找到了使错误消失的解决方案。管理 NuGet 包

单击“管理 NuGet 包”,然后在浏览区域中将“Microsoft.SharePoint.dll”磁带,当您执行此操作时,您希望以与您的 .Net Framework 兼容的方式选择正确版本的 NuGet 包,然后单击安装。当你回到代码之后,你会看到错误消失了。为了更清楚,请在评论中联系我。

于 2019-05-14T11:36:21.490 回答