Windows Sharepoint Services - FullTextSqlQuery 文档库无法找到由系统帐户创建的项目

发布于 2024-08-28 05:16:34 字数 4806 浏览 5 评论 0原文

我们创建了一个 ASP.NET Web 应用程序,用于将文件上传到 WSS Doc Libary。这些文件将添加到库中的“系统帐户”下。 FullTextSqlQuery 类用于搜索文档库项目。但它只搜索由 Windows 用户帐户(如“管理员”)上传的文件,并忽略由“系统帐户”上传的文件。因此,即使我们在文档库中有必要的数据,搜索结果也是空的。这可能是什么原因? 代码如下:

public static List GetListItemsFromFTSQuery(string searchText) { 字符串 docLibUrl = "http://localhost:6666/Articles%20Library/Forms/AllItems. aspx"; 列表项 = 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;
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

明月夜 2024-09-04 05:16:34

尝试将查询中的 freetext 子句修改为:

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

Try amending the freetext clause in your query to be :

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文