我的要求是删除网站下隐藏/未使用的网页部分。 也无法获取网站下所有页面的列表。 需要帮助
答案 0 :(得分:1)
伙计,找到上述问题的部分代码
使用(SPSite oSite = new> SPSite(cbWebSite.SelectedItem.ToString())) 使用(SPWeb web = oSite.OpenWeb())
dtWebParts = (System.Data.DataTable)CreateDataTableForUnusedWebParts();
System.Data.DataTable dtWebPartReport = new System.Data.DataTable(); DataColumn dtCol = new DataColumn(); dtCol.ColumnName = COLUMN_WEBAPP_NAME; dtCol.DataType = System.Type.GetType("System.String"); dtWebPartReport.Columns.Add(dtCol); . . .
调用该函数生成报告。
private void generateWebPartReportForWeb(SPWeb oWeb, SPSite oSite)
{
try { //If team Site then read homepage foreach (SPFile rootFile in oWeb.Files) { checkPageForWebParts(oWeb, oSite,rootFile); } foreach (SPList oList in oWeb.Lists) { if (oList.BaseType == SPBaseType.DocumentLibrary) { lstName = oList.Title.ToString(); spDocumentLibrary =(SPDocumentLibrary)oWeb.Lists[lstName]; if (spDocumentLibrary.Title.ToString() !="Master Page Gallery" && spDocumentLibrary.Title.ToString() !="dataconnectionLib" && spDocumentLibrary.Title.ToString() !="Form Templates" && spDocumentLibrary.Title.ToString() !="Images" && spDocumentLibrary.Title.ToString() !="List Template Gallery" & spDocumentLibrary.Title.ToString() !="Scripts" && spDocumentLibrary.Title.ToString() !="Site Template Gallery" & spDocumentLibrary.Title.ToString() !="Style Library" && spDocumentLibrary.Title.ToString() !="Web Part Gallery" && spDocumentLibrary.Title.ToString() !="Workflows") { foreach (SPListItem spListItem in spDocumentLibrary.Items) { spFile = spListItem.File; checkPageForWebParts(oWeb, oSite,spFile); } } } } if (oWeb.Webs.Count > 0) { foreach (SPWeb subsite in oWeb.Webs) { generateWebPartReportForWeb(subsite, oSite); } } DataView dv = dtWebParts.DefaultView; dv.Sort = "Document Library Path ASC"; dataGridView1.DataSource = dtWebParts; dataGridView1.Update(); }
private void checkPageForWebParts(SPWeb oWeb,SPSite oSite, SPFile spFile) { try { string[] strFileName = spFile.Name.Split('.'); string fileExtension = strFileName[strFileName.Length - 1].ToUpper(); if (fileExtension.ToUpper() == "ASPX") { using (SPLimitedWebPartManager wpm = oWeb.GetLimitedWebPartManager(spFile.Url, PersonalizationScope.Shared)) { foreach (System.Web.UI.WebControls.WebParts.WebPart wp in wpm.WebParts) { if (wp.IsClosed || wp.Hidden) { DataRow dr = dtWebParts.NewRow(); if (oSite.WebApplication.Name != null) dr[COLUMN_WEBAPP_NAME] = oSite.WebApplication.Name; if (oSite.Url != null) dr[COLUMN_SITECOLLECTION_NAME] = oSite.Url; if (oWeb.Name != null) dr[COLUMN_SUBSITE_NAME] = oWeb.Name; if (oWeb.Url != null) dr[COLUMN_DOCLIB_PATH] =cbWebApp.SelectedItem.ToString() + spFile.ServerRelativeUrl;//oWeb.Url + "/" + spDocumentLibrary.ToString(); if (spFile.Name != null) dr[COLUMN_DOCNAME] = spFile.Name; if (wp.Title != null) dr["WebPart Name"] = wp.Title; if (wp.IsClosed) dr["Hidden/Closed"] = "Closed"; else if (wp.Hidden) dr["Hidden/Closed"] = "Hidden"; dtWebParts.Rows.Add(dr); dtWebParts.AcceptChanges(); } } } } }
答案 1 :(得分:0)
此link对您有所帮助。
protected override void CreateChildControls()
{
list = new BulletedList();
WebPartZoneCollection zones = this.WebPartManager.Zones;
foreach (WebPartZone zone in zones)
{
WebPartCollection webparts = zone.WebParts;
foreach (WebPart webpart in webparts)
{
**You can check webpart.hidden property here.**
list.Items.Add(
string.Format("{0} ({1}), {2}",
webpart.Title, webpart.GetType().Name,
zone.DisplayTitle));
}
}
this.Controls.Add(list);
}