c# - 使用 asp.net Web API 将 SharePoint 列表数据检索到 JSON 格式的数据表中
问题描述
我正在尝试使用 asp.net Web API MVC 应用程序从 SharePoint 列表中获取数据,然后将其加载到数据表中,最后将其作为 JSON 格式的 API 输出提供。
我试图从 SharePoint 列表中获取数据,但 SharePoint 给出null
了结果。
我期望将数据加载到我的数据表中,并且 API 应该将该数据作为 JSON 输出提供。
解决方案
你的问题不清楚。不过,我试过了。
这是我在控制台应用程序中使用的代码。
public static SPListItemCollection GetCollection()
{
string listName = 'Your List Name';
string queryStr = "<Where><Eq><FieldRef Name='Title''/><Value Type='Text'>" + YourValue + "</Value></Eq></Where><OrderBy><FieldRef Name='ID' Ascending='FALSE'/></OrderBy>";
SPListItemCollection oCollection = GetListItemCollectionByQuery(listName, queryStr);
return oCollection;
}
public static SPListItemCollection GetListItemCollectionByQuery(string ListName, string queryText)
{
SPListItemCollection spListItemCollection = null;
string webUrl = Your Site URL;
try
{
using (SPSite oSPsite = new SPSite(webUrl))
{
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
string listName = ListName;
SPList spList = oSPWeb.Lists[listName];
if (spList != null)
{
SPQuery spQuery = new SPQuery();
spQuery.Query = queryText;
spListItemCollection = spList.GetItems(spQuery);
}
}
}
}
catch (Exception ex)
{
HandleException(ex);
}
return spListItemCollection;
}
此外,您需要检查此Get DataTable
我希望它可以帮助:)
推荐阅读
- android - 如何在不更改旧代码的情况下将 Glide 3.7 升级到 Glide 4.7
- c++ - 无法访问超过 255 个的 Modbus 寄存器 SimpleModbus
- amazon-web-services - 如何配置 elb 和服务器之间的 keep-alive 时间?
- c++ - 类初始化中的静态 lambda
- hyperledger-fabric - 如何在 Hyperledger Composer of Fabric 的不同通道中处理一个通道中引发的事件?
- c# - 避免“引入 FOREIGN KEY 约束可能导致循环或多个级联路径”
- javascript - AJAX 后生成的链接不起作用
- vba - 经典的 asp 布尔到字符串语言
- macos - 如何使用原生 API 在 MacOS 上获取设备像素比?
- c# - Web api 代码 - 加载失败 - 访问控制允许来源