views:

352

answers:

1

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;
    }
A: 

Try amending the freetext clause in your query to be :

... freetext(*, '" + searchText + "' ....

derekadk