Windows Sharepoint Services - FullTextSqlQuery Document library Unable to find items created by SYST

Posted by Ashok on Stack Overflow See other posts from Stack Overflow or by Ashok
Published on 2010-04-05T07:40:08Z Indexed on 2010/04/05 7:43 UTC
Read the original article Hit count: 1136

We have created an ASP.NET web app that upload files to WSS Doc Libary. The files get added under 'SYSTEM ACCOUNT' in the library. The FullTextSqlQuery class is used to search the document libary items. But it only searches files that has been uploaded by a windows user account like 'Administrator' and ignores the ones uploaded by 'SYSTEM ACCOUNT'. As a result the search results are empty even though we have the necessary data in the document library. What could be the reason for this? The code is given below:

public static List GetListItemsFromFTSQuery(string searchText) { string docLibUrl = "http://localhost:6666/Articles%20Library/Forms/AllItems.aspx"; List items = new List(); DataTable retResults = new DataTable();

        SPSecurity.RunWithElevatedPrivileges(delegate
                                                 {
                                                     using (SPSite site = new SPSite(docLibUrl))
                                                     {
                                                         SPWeb CRsite = site.OpenWeb();
                                                         SPList ContRep = CRsite.GetListFromUrl(docLibUrl);

                                                         FullTextSqlQuery fts = new FullTextSqlQuery(site);
                                                         fts.QueryText =
                                                             "SELECT Title,ContentType,Path FROM portal..scope() WHERE freetext('" +
                                                             searchText +
                                                             "') AND (CONTAINS(Path,'\"" +
                                                             ContRep.RootFolder.ServerRelativeUrl + "\"'))";
                                                         fts.ResultTypes = ResultType.RelevantResults;
                                                         fts.RowLimit = 300;
                                                         if (SPSecurity.AuthenticationMode != System.Web.Configuration.AuthenticationMode.Windows)

                                                             fts.AuthenticationType = QueryAuthenticationType.PluggableAuthenticatedQuery;

                                                         else

                                                             fts.AuthenticationType = QueryAuthenticationType.NtAuthenticatedQuery;


                                                         ResultTableCollection rtc = fts.Execute();
                                                         if (rtc.Count > 0)
                                                         {

                                                             using (
                                                                 ResultTable relevantResults =
                                                                     rtc[ResultType.RelevantResults])
                                                                 retResults.Load(relevantResults,
                                                                                 LoadOption.OverwriteChanges);

                                                             foreach (DataRow row in retResults.Rows)
                                                             {
                                                                 if (!row["Path"].ToString().EndsWith(".aspx"))
                                                                     //if (row["ContentType"].ToString() == "Item")  
                                                                 {
                                                                     using (
                                                                         SPSite lookupSite =
                                                                             new SPSite(row["Path"].ToString()))
                                                                     {
                                                                         using (SPWeb web = lookupSite.OpenWeb())
                                                                         {
                                                                             SPFile file =
                                                                                 web.GetFile(row["Path"].ToString());
                                                                             items.Add(file.Item);

                                                                         }
                                                                     }
                                                                 }
                                                             }

                                                         }

                                                     } //using ends here
                                                 });
        return items;
    }

© Stack Overflow or respective owner

Related posts about sharepoint-api

Related posts about document-library