c# - 我的代码中有一个错误“找不到类型或命名空间名称‘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);
}
}
}
}
在正确的位置添加我下载的包后,我预计错误会消失,但它仍然存在。请帮忙!
解决方案
安装 nuget 包,这是使用它的最佳方式。您可以使用包管理器 UI (Visual Studio) 或包管理器控制台 (Visual Studio) 进行安装,请参阅。
注 1:SPSite
、SPWeb
和是命名空间中的SPList
类。SPField
Microsoft.SharePoint
注意 2:您的代码中有:using Microsoft.SharePoint;
和using Microsoft.SharePoint.Client;
,Microsoft.SharePoint
和Microsoft.SharePoint.Client
是两个不同的 nuget 包。
岳
推荐阅读
- c# - C# 如何使用 datagridview_comboboxes 填充数据网格视图
- r - 有条件地从 R 中的列表中删除项目
- excel - InStr 在特定单元格中查找确切数字
- javascript - '-' 在 v-bind:style / Vue.js 中
- reactjs - 反应路由器
不添加活动类 - matplotlib - 在 matplot lib 上以灰度显示图像
- firebase - 如何在 map() 中使用异步代码(Flutter、Firestore)
- c++ - 如何在文件中将 Hi 替换为 Bye
- python - Python:用“常规”替代品替换最小化的特殊字符
- r - 在 R 中具有多个条件的 count_if (EXPSS)