用QuickPart实现递归获取站点下的列表(比Webpart快)
很简单的代码.
--------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
public partial class BBSWebList : System.Web.UI.UserControl
{
private String _sDebug = "";
private System.Text.StringBuilder builder = new System.Text.StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
SPSite siteColl = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;
using (SPSite site1 = new SPSite(siteColl.ID))
{
using (SPWeb web = site1.OpenWeb(site.ID))
{
this.getWebLists(web);
//写表格
this.LabList.Text = builder.ToString();
}
}
}
/// <summary>
/// getWebLists 获取一个站点的所有列表信息
/// (包括文档库和列表库)
/// </summary>
private void getWebLists(SPWeb web)
{
try
{
//站点间的换行
if (builder.ToString().Length !=0)
{
builder.AppendLine("<br/>");
}
//站点外框
builder.AppendLine("<table style='BORDER-RIGHT: #ff0066 1px solid; BORDER-TOP: #ff0066 1px solid; BORDER-LEFT: #ff0066 1px solid; WIDTH: 100%; BORDER-BOTTOM: #ff0066 1px solid'>");
builder.AppendLine("<tr>");
builder.AppendLine("<td>");
//站点标题
builder.AppendLine("<table style='width:100%; align:center;font-weight: bold ;border-width:medium thin medium thin; align:center;'cellpadding=0px cellspacing=0px>");
builder.AppendLine("<tr>");
builder.AppendLine("<td style='background-color:#ff5c26' width:100% height=30px> <a style='font-family: 微软雅黑; color: #3c3c3c;' href='" + web.Url + "'>" + web.Title + "</a></td>");
builder.AppendLine("</tr>");
builder.AppendLine("</table>");
//表头
//<table style="border-right: 1px; border-top: 1px; border-left: 1px; border-bottom: 1px" border="0" cellpadding="0" cellspacing="0">
//border="0" cellpadding="0" cellspacing="0"
builder.AppendLine("<table style='width:100%; align:center; font-family:华文新魏; background-color:#ffcc99'; border=0px ;cellpadding=0px ;cellspacing=0px>");
builder.AppendLine("<tr> ");
builder.AppendLine("<td align=center width=25px height=20px></td>");
builder.AppendLine("<td align=left >板块</td>");
builder.AppendLine("<td align=center >总贴数</td>");
builder.AppendLine("<td align=center >上次更新时间</td>");
builder.AppendLine("</tr>");
foreach (SPList list in web.Lists)
{
if (list.BaseTemplate.ToString().Trim() == "DiscussionBoard")
{
//builder.AppendLine("<tr>");
//builder.AppendLine("<td width=100% colspan=3>");
//builder.AppendLine("<table style='width:100%; align:center; font-family:华文新魏; background-color:#fff8de'; border=0px ;cellpadding=0px ;cellspacing=0px>");
builder.AppendLine("<tr>");
builder.AppendLine("<td style='background-color:#fff8de;'height=35px width=35px align=center ><img src='_layouts/images/21.gif'/></td>");
builder.AppendLine("<td style='background-color:#fff8de;'> <a href='" + list.DefaultViewUrl + "'>" + list.Title + "</a><br> " + list.Description + "</td>");
builder.AppendLine("<td style='background-color:#fff8de;'width=60px align=center >" + list.ItemCount + "</td>");
builder.AppendLine("<td style='background-color:#fff8de;'width=120px align=center >" + list.LastItemModifiedDate.ToLocalTime() + "</td>");
builder.AppendLine("</tr>");
//builder.AppendLine("</table>");
//builder.AppendLine("</td>");
//builder.AppendLine("</tr>");
}
}
builder.AppendLine("</table>");
//站点外框
builder.AppendLine("</td>");
builder.AppendLine("</tr>");
builder.AppendLine("</table>");
//递归获取站点下的子站点
foreach (SPWeb subWeb in web.Webs)
{
this.getWebLists(subWeb);
}
}
catch (Exception ex)
{
_sDebug += "</br> getWebLists Error:" + ex.Message;
}
}