c# - How to convert a FullTextSqlQuery result to an SPListItem? -
i though following code work every time @ file.item;
null. should doing different?
microsoft.office.server.search.query.fulltextsqlquery query = new microsoft.office.server.search.query.fulltextsqlquery(sitecollection); query.querytext = "select title, path, description, write, rank, size scope() \"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; } } //} }
if know item try spweb.getlistitem
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.getlistitem.aspx
the file might not exist, check spfile.exists before using of spfile's properties
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.exists.aspx
Comments
Post a Comment