The SiteRequest
form will be used to log the site requests with the related configuration settings and approval status. As we need this form to be available globally we will use an application page, which is deployed via our feature and available throughout the farm. This will also enable us to show or hide fields as needed and include advanced business logic, which provides significantly more flexibility than standard SharePoint list forms.
To get started we will need to map a folder within the Layouts
directory.
To map the folder and create the files:
SPBlueprintsSiteCreation
without the period. RequestSite.aspx
.The standard application page is added to the project, which comprises two files we will now need to build. They are:
RequestSite.aspx:
The design surface for controlsRequestSite.aspx.cs:
The code behind file for control logic and eventsThe standard application page template includes the control and resource import statements at the top followed by the content placeholder controls.
To build the Request Site page:
Request Site Collection
to the PlaceHolderPageTitle
control shown as follows:<asp:ContentID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server"> Request Site Collection </asp:Content>
Request Site Collection
to the PlaceHolderPageTitleInTitleArea
control shown as follows:<asp:ContentID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" > Request Site Collection </asp:Content>
PlaceHolderMain
control. The format and referenced styles will render the form like the standard SharePoint list forms. A label control will be added to provide status and any error messages that need to be displayed.<table class="ms-formtable" style="margin-top: 8px;"border="0" cellpadding="0" id="formTbl" cellspacing="0" width="100%"> <tr> <td valign="top" class="ms-formbody" colspan="2" id="Td5"> <asp:LabelID="Status"runat="server"></asp:Label> </td> </tr>
Title
property is shown as follows:<tr> <td nowrap="true" valign="top" width="165px" class="ms- formlabel"><h3 class="ms- standardheader"><a name="SPBookmark_Title"></a> Site Title</h3> </td> <td valign="top" class="ms- formbody" width="450px" id="SPFieldFile"> <SharePoint:InputFormTextBox ID="Title" runat="server" ControlMode="New" Width="300"> </SharePoint:InputFormTextBox> </td> </tr>
PriOwner
property is shown as follows:<tr> <td nowrap="true" valign="top" width="165px" class="ms-formlabel"><h3 class="ms-standardheader"> <a name="SPBookmark_PriOwner"></a>Primary Owner</h3> </td> <td valign="top" class="ms-formbody" width="450px" id="Td2"> <SharePoint:PeopleEditorID="PriOwner" runat="server" MultiSelect="false" MaximumEntities="1" Width="300"/> </td> </tr>
<tr> <td nowrap="true" valign="top" width="165px" class="ms-formlabel"><h3 class="ms-standardheader"> <a name="SPBookmark_Path"></a>Site Category</h3> </td> <td valign="top" class="ms-formbody" width="450px" id="Td3"> <asp:DropDownList ID="SiteCategory" runat="server" Width="300"> </asp:DropDownList> </td> </tr>
CheckBox
control for each of the features available. The form row is shown as follows:<tr> <td nowrap="true" valign="top" width="165px" class="ms-formlabel"><h3 class="ms-standardheader"> <a name="SPBookmark_URL"></a>Document ID Service</h3> </td> <td valign="top" class="ms-formbody" width="450px" id="Td6"> <asp:CheckBox ID="SiteFeatureDocID" runat="server"/> </td> </tr>
<tr> <td colspan="2" align="right"> <asp:Button ID="Save" runat="server" Text="Save"/> </td> </tr> </table> </asp:Content>
The code behind this application page is used to handle the form processing during the Page_Load()
method:
SiteCategory
form input field.if (Page.IsPostBack) { this.Status.Text = ""; try { // Site Categorization string quotaTemplate = ""; string managedPath = ""; string siteTemplate = ""; switch (this.SiteCategory.SelectedValue) { case"Project Site": quotaTemplate = "Project Collab"; siteTemplate = "Project Site"; managedPath = "projects/"; break; case"Extranet Site": quotaTemplate = "Extranet Collab"; siteTemplate = "Extranet Site"; managedPath = "extranet/"; break; default: quotaTemplate = "Team Collab"; siteTemplate = "Team Site"; managedPath = "sites/"; break; }
string listName = this.Web.Site.WebApplication.Properties["SiteRequestList"]. ToString(); string listPath = this.Web.Site.WebApplication.Properties["SiteRequestSite"]. ToString(); using (SPSite site = newSPSite(listPath)) { using (SPWeb web = site.RootWeb) {
Person
or Group
field in a SharePoint list, it is necessary to pass in an SPUser
object when updating the list item. Before we can set the list value we will need to define an SPUser
object and set it to the form value if one was provided.SPUser userPriOwner = null; if (this.PriOwner.Accounts.Count > 0) { userPriOwner = web.EnsureUser(this.PriOwner.Accounts[0].ToString()); }
SiteCategory
selection box drives the field values for the managed path, site template, and quota template. We are also setting the request's status to Pending Approval
, which is what we have determined is the starting status for our requests. After all of the desired fields are set, we need to call the Update()
method so that they are saved back to the list.SPListItem newEntry = web.Lists[listName].Items.Add(); newEntry["Title"] = this.Title.Text; newEntry["Description"] = this.Description.Text; newEntry["PriOwner"] = userPriOwner; newEntry["Path"] = managedPath; newEntry["URLName"] = this.URLName.Text; newEntry["Template"] = siteTemplate; newEntry["Quota"] = quotaTemplate; newEntry["Status"] = "Pending Approval"; newEntry["SiteFeatureDocID"] = this.SiteFeatureDocID.Checked; newEntry["SiteFeaturePub"] = this.SiteFeaturesPub.Checked; newEntry["SiteFeatureActions"] = this.SiteFeaturesActions.Checked; newEntry["SiteFeaturesWebParts"] = this.SiteFeaturesWebParts.Checked; newEntry["WebFeaturesContentOrg"] = this.WebFeaturesContentOrg.Checked; newEntry["WebFeaturesMetaNav"] = this.WebFeaturesMetaNav.Checked; newEntry["WebFeaturesPub"] = this.WebFeaturesPub.Checked; newEntry["WebFeaturesWikiPage"] = this.WebFeaturesWikiPage.Checked; newEntry.Update();
if
block. else
block.else { this.SiteCategory.Items.Add("Team Site"); this.SiteCategory.Items.Add("Project Site"); this.SiteCategory.Items.Add("Extranet Site"); }
3.145.2.184