moss2010 仿内容查询部件代码

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using System.Data;

namespace  All_Tongzi.VisualWebPart1
{
    public partial class VisualWebPart1UserControl : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.CheckBoxListTsta.Items.Clear();
                using (SPSite site = SPContext.Current.Site)
                {
                    foreach (SPWeb web in site.AllWebs)
                    {

                        foreach (SPList list in web.Lists)
                        {
                            if (list.BaseTemplate == SPListTemplateType.Announcements)
                            {
                                foreach (SPListItem item in list.Items)
                                {
                                    string vl = web.Title + " " + list.Title + " " + item["Title"].ToString();
                                    this.CheckBoxListTsta.Items.Add(vl);
                                }
                            }
                        }
                    }
                }

                DataTable dtable = new DataTable();
                dtable.Columns.Add(new DataColumn("Title"));
                dtable.Columns.Add(new DataColumn("Score"));
                dtable.Columns.Add(new DataColumn("Editor"));
                dtable.Columns.Add(new DataColumn("Modified"));
                dtable.Columns.Add(new DataColumn("url"));
                using (SPSite site = SPContext.Current.Site)
                {
                    foreach (SPWeb web in site.AllWebs)
                    {

                        foreach (SPList list in web.Lists)
                        {
                            if (list.BaseTemplate == SPListTemplateType.Announcements)
                            {
                                foreach (SPListItem item in list.Items)
                                {
                                    DataRow dr = dtable.NewRow();
                                    dr["Title"]=item["Title"].ToString();
                                    dr["Editor"] = item["Editor"].ToString().Split('#')[1].ToString();
                                    dr["Modified"] = item["FileRef"].ToString();
                                    dr["Score"] = web.Title;
                                    string url=site.Url+""+ item["FileRef"].ToString().Replace("1_.000","")+"DispForm.aspx?ID="+item["ID"].ToString();
                                    dr["url"] = url;
                                    //string vl = web.Title + " " + list.Title + " " + item["Title"].ToString();
                                    dtable.Rows.Add(dr);
                                }
                            }
                        }
                    }
                }
                this.GridView1.DataSource = dtable;
                this.GridView1.DataBind();
            }
        }
    }
}

你可能感兴趣的:(OS)