Wss搜索
昨天在整理硬盘的时候,发现一个不错的Wss搜索Demo.都不记得什么时候出来的.然后自己在自己的机器上面测试下,感觉还不错哦。 .
根据用户权限搜索,不同的用户,看到的网站不一样哦。有权限区别的哦.是对列表上面的搜索.把代码帖出来希望下面有些对方可以帮助SharePoint的爱好者!
效果图:

呵呵,感觉是不是很不错?

至少我感觉很棒!!!
最后帖代码:这是是我的习惯,开发人员有代码还是容易理解些.我不习惯来虚东西!
CS代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Microsoft.SharePoint;
namespace WSSsearch
{
public partial class WSSSearch : System.Web.UI.UserControl
{
protected SPWeb _web;
private string row = "<TR><TD><IMG SRC='{0}'</TD><TD><A HREF='{1}'>{2}</A></TD>" +
"<TD>{3}</TD><TD>{4}</TD></TR>";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
this.FillListSites();
}
#region IUserControl Members
public Microsoft.SharePoint.SPWeb SPWeb
{
get
{
return this._web;
}
set
{
this._web = SPContext.Current.Web;
this._web = value;
}
}
#endregion
#region Private Members
private void FillListSites()
{
//-- add all sites
this.listSites.Items.Add(new ListItem("All Sites", string.Empty));
//-- add current site
this._web = SPContext.Current.Web;
this.listSites.Items.Add(new ListItem("Current: " + this._web.Title, this._web.ID.ToString()));
//-- add the subsites that can be accessed by the user
foreach (SPWeb subweb in this._web.GetSubwebsForCurrentUser())
{
this.listSites.Items.Add(new ListItem(subweb.Title, subweb.ID.ToString()));
}
}
private void Search()
{
//-- preparation
string keyword = this.textBoxKeyword.Text;
string scope = this.listSites.SelectedItem.Value;
StringBuilder sb = new StringBuilder();
//-- loop over
if (keyword != string.Empty)
{
if (scope != string.Empty)
{
//-- only go for the selected site
// SPContext.Current.Web
SPWeb web = SPContext.Current.Web.Site.OpenWeb();
if (web != null)
this.SearchList(web, ref sb, keyword);
}
else
{
//-- have the current site
this.SearchList(this._web, ref sb, keyword);
//-- and all the sub sites
foreach (SPWeb web in this._web.GetSubwebsForCurrentUser())
{
this.SearchList(web, ref sb, keyword);
}
}
}
//-- output the result
if (sb.ToString() == string.Empty)
literalResults.Text = "<BR><B>Sorry, there are no results.</B>";
else
literalResults.Text = "<TABLE WIDTH='100%' STYLE='border:solid 1px silver'>" + sb.ToString() + "</TABLE>";
}
public void SearchList(SPWeb webToProcess, ref StringBuilder sb, string keyword)
{
SPWeb web =SPContext.Current.Web.Site.OpenWeb(webToProcess.ID);
SPSearchResultCollection resLists = web.SearchListItems(keyword);
foreach (SPSearchResult resList in resLists)
{
sb.AppendFormat(row, resList.IconUrl, resList.Url,
resList.Title, resList.ModifiedBy,
resList.DateLastModified.ToShortDateString());
}
}
#endregion
protected void buttonSearch_Click(object sender, EventArgs e)
{
this.Search();
}
ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WSSSearch.ascx.cs" Inherits="WSSsearch.WSSSearch" %>
<P>
<TABLE id="Table1" cellSpacing="1" cellPadding="2" width="100%" border="0">
<TR>
<TD>
<P>Search for
<asp:TextBox id="textBoxKeyword" runat="server"></asp:TextBox> in
<asp:DropDownList id="listSites" runat="server" Width="176px" OnSelectedIndexChanged="listSites_SelectedIndexChanged"></asp:DropDownList>
<asp:Button id="buttonSearch" runat="server" Text="Search" OnClick="buttonSearch_Click"></asp:Button></P>
</TD>
</TR>
<TR>
<TD>
<asp:Literal id="literalResults" runat="server"></asp:Literal></TD>
</TR>
</TABLE>
</P>
<P> </P>
代码不是最后.只是给我们开发同胞们.找不到demo的时候,有一个参考的!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述