首页 > 解决方案 > 我的代码中有一个错误“找不到类型或命名空间名称‘spsite’”,我不知道如何解决它

问题描述

我编写了一个包含 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);
               }
           }
       }
   }

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

标签: c#visual-studiosharepointssisspsite

解决方案


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

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

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


推荐阅读