Operation is not valid due to the current state of the object.

baidu_15160663 2017-02-20 02:46:25
KeywordQuery keywordQuery = new KeywordQuery(site);
这个一直报Operation is not valid due to the current state of the object.
同样的代码在控制台应用程序却没有问题,大家帮忙分析分析感激不尽


Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite thisSite = new SPSite("http://localhost:9090/"))
{
var thisWeb = thisSite.RootWeb;
thisWeb.AllowUnsafeUpdates = true;
SPUser user = thisWeb.EnsureUser("mossadmin");
string weburl = "http://localhost:9090/";
using (SPSite site = new SPSite(weburl, user.UserToken))
{
KeywordQuery keywordQuery = new KeywordQuery(site);
keywordQuery.QueryText = "huanghailong";
SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
var resultTable = resultTables.FirstOrDefault();
DataTable dataTable = resultTable.Table;
Console.WriteLine(dataTable.Rows.Count);
}
}
});
...全文
2164 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
段传涛 2017-04-01
  • 打赏
  • 举报
回复
从代码,没有看出错误来。 调试一下吧,看看抛出什么错误。
Frank_CAU 2017-03-21
  • 打赏
  • 举报
回复
你的这个有问题的程序是在w3wp中运行的么?看你的这个code好像是Console的程序的code,可否把有问题的code复制出来,另外请问一下你的这个页面后台的code是在什么中运行?是在SharePoint的环境中运行的还是另外一个和SharePoint无关的ASP.Net站点?
霖雨 版主 2017-02-21
  • 打赏
  • 举报
回复
var thisWeb = thisSite.RootWeb; 改一下呢 using(spweb thisWeb=thisSite.openweb(thisSite.RootWeb.Id)) 建议调试一下,看看哪句报错了。。如果是webservice,可以try。。。catch一下,把错误日志记录下来
Justin-Liu 2017-02-20
  • 打赏
  • 举报
回复
在控制台程序没问题的话,你这个有问题的是在什么类型的project下?

3,245

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 SharePoint
社区管理员
  • SharePoint社区
  • 霖雨 - LinyuLoveTJ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧