using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Publishing;
using System.Web.UI.WebControls.WebParts;
namespace SPHelper
{
class Helper
{
public static void AddLibrary(SPWeb web, string libraryname, string description, string docTemplateName, string listTemplateName)
{
web.AllowUnsafeUpdates = true;
SPDocTemplateCollection docColl = web.DocTemplates;
SPDocTemplate WebpartPagetemplate = null;
SPListTemplateCollection tem = web.ListTemplates;
SPListTemplate lstTemplate = null;
foreach (SPDocTemplate doctemplate in docColl)
{
if (doctemplate.Name.Equals(docTemplateName))
{
WebpartPagetemplate = doctemplate;
}
}
foreach (SPListTemplate template in tem)
{
if (template.Name.Equals(listTemplateName))
{
lstTemplate = template;
}
}
web.Lists.Add(libraryname, description, lstTemplate, WebpartPagetemplate);
web.Update();
}
public static void AddPage(SPWeb web, string pagename,string pagelayoutname)
{
PageLayout currPageLayout = null;
web.AllowUnsafeUpdates = true;
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
string pageName = pagename;
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
foreach (PageLayout pagelayout in pageLayouts)
{
if (pagelayout.Name.Equals(pagelayoutname))
{
currPageLayout = pagelayout;
}
}
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName, currPageLayout);
newPage.ListItem[FieldId.PublishingPageContent] = string.Empty;
newPage.ListItem.Update();
newPage.Update();
newPage.CheckIn(string.Empty);
}
public static void AddWebPartToPage(SPWeb web, string pageurl, string ucpath, string wptitle, string zoneid, int zoneIndex)
{
using (SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(pageurl, PersonalizationScope.Shared))
{
UserControlViewer.UserControlViewer webpart = new UserControlViewer.UserControlViewer();
webpart.UserControlVirtualPath = ucpath;
webpart.ZoneID = zoneid;
webpart.Title = wptitle;
wpManager.AddWebPart(webpart, zoneid, zoneIndex);
}
}
public const string doctemplatename = "Web Part page";
public const string listtemplatename = "Document Library";
public const string pagelayout = "BlankWebPartPage.aspx";
//Helper.AddLibrary(properties.Web, "Default", "Annonymouns Access files are available in this Library",Helper.doctemplatename,Helper.listtemplatename);
//Helper.AddPage(properties.Web, "EURegister.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "PeopleAwards.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "NPOAwards.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "RCIAwards.aspx", Helper.pagelayout);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Publishing;
using System.Web.UI.WebControls.WebParts;
namespace SPHelper
{
class Helper
{
public static void AddLibrary(SPWeb web, string libraryname, string description, string docTemplateName, string listTemplateName)
{
web.AllowUnsafeUpdates = true;
SPDocTemplateCollection docColl = web.DocTemplates;
SPDocTemplate WebpartPagetemplate = null;
SPListTemplateCollection tem = web.ListTemplates;
SPListTemplate lstTemplate = null;
foreach (SPDocTemplate doctemplate in docColl)
{
if (doctemplate.Name.Equals(docTemplateName))
{
WebpartPagetemplate = doctemplate;
}
}
foreach (SPListTemplate template in tem)
{
if (template.Name.Equals(listTemplateName))
{
lstTemplate = template;
}
}
web.Lists.Add(libraryname, description, lstTemplate, WebpartPagetemplate);
web.Update();
}
public static void AddPage(SPWeb web, string pagename,string pagelayoutname)
{
PageLayout currPageLayout = null;
web.AllowUnsafeUpdates = true;
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
string pageName = pagename;
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
foreach (PageLayout pagelayout in pageLayouts)
{
if (pagelayout.Name.Equals(pagelayoutname))
{
currPageLayout = pagelayout;
}
}
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName, currPageLayout);
newPage.ListItem[FieldId.PublishingPageContent] = string.Empty;
newPage.ListItem.Update();
newPage.Update();
newPage.CheckIn(string.Empty);
}
public static void AddWebPartToPage(SPWeb web, string pageurl, string ucpath, string wptitle, string zoneid, int zoneIndex)
{
using (SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(pageurl, PersonalizationScope.Shared))
{
UserControlViewer.UserControlViewer webpart = new UserControlViewer.UserControlViewer();
webpart.UserControlVirtualPath = ucpath;
webpart.ZoneID = zoneid;
webpart.Title = wptitle;
wpManager.AddWebPart(webpart, zoneid, zoneIndex);
}
}
public const string doctemplatename = "Web Part page";
public const string listtemplatename = "Document Library";
public const string pagelayout = "BlankWebPartPage.aspx";
//Helper.AddLibrary(properties.Web, "Default", "Annonymouns Access files are available in this Library",Helper.doctemplatename,Helper.listtemplatename);
//Helper.AddPage(properties.Web, "EURegister.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "PeopleAwards.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "NPOAwards.aspx", Helper.pagelayout);
//Helper.AddPage(properties.Web, "RCIAwards.aspx", Helper.pagelayout);
}
}