我虽然以下代码可以使用,但每次我查看file.Item;
时它都是null。我应该做些不同的事吗?
Microsoft.Office.Server.Search.Query.FullTextSqlQuery query = new Microsoft.Office.Server.Search.Query.FullTextSqlQuery(siteCollection);
query.QueryText = "SELECT Title, Path, Description, Write, Rank, Size from scope() where \"scope\" = 'SocialNetworking'";
query.ResultTypes = Microsoft.Office.Server.Search.Query.ResultType.RelevantResults;
//query.RowLimit = Int32.MaxValue;
query.TrimDuplicates = true;
query.EnableStemming = false;
query.IgnoreAllNoiseQuery = true;
query.KeywordInclusion = Microsoft.Office.Server.Search.Query.KeywordInclusion.AllKeywords;
query.Timeout = 0x2710;
query.HighlightedSentenceCount = 3;
query.SiteContext = new Uri(siteCollection.Url);
query.AuthenticationType = Microsoft.Office.Server.Search.Query.QueryAuthenticationType.NtAuthenticatedQuery;
Microsoft.Office.Server.Search.Query.ResultTableCollection queryResults = query.Execute();
Microsoft.Office.Server.Search.Query.ResultTable queryResultsTable = queryResults[Microsoft.Office.Server.Search.Query.ResultType.RelevantResults];
DataTable queryDataTable = new DataTable();
queryDataTable.Load(queryResultsTable, LoadOption.OverwriteChanges);
foreach (DataRow dr in queryDataTable.Rows)
{
//if (dr["ContentType"].ToString() == "Item")
//{
using (SPSite lookupSite = new SPSite(dr["Path"].ToString()))
{
using (SPWeb web = lookupSite.OpenWeb())
{
SPFile file = web.GetFile(dr["Path"].ToString());
SPListItem li = file.Item;
}
}
//}
}
答案 0 :(得分:1)
如果你知道它是一个项目,请尝试SPWeb.GetListItem
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getlistitem.aspx
该文件可能也不存在,请在使用任何SPFile属性之前检查SPFile.Exists
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.exists.aspx