SharePoint - ACME Project

44
Mauro Sist SharePoint Portfolio (586) 264-6436 [email protected]

description

 

Transcript of SharePoint - ACME Project

Page 1: SharePoint - ACME Project

Mauro Sist

SharePoint Portfolio (586) 264-6436

[email protected]

Page 2: SharePoint - ACME Project

SHAREPOINT ACME SOLUTION PROJECT

Introduction:For this project, I was responsible for developing a SharePoint Solutions portal for a large Towing Company Service Company that I will fictitiously name ACME. The project as deployed in this document is based on the specifications provided by Nick Kellett at Griffon Solutions (www.griffonsolutions.com).The ACME Company would like to create an area called the "Solution Portal" for their developers to organize and manage their projects. This would also provide some help for the rest of the ACME’s staff that need to use these projects. Managers would also insight into the projects they are working on, as well as the ability to submit feature requests to the developers.The purpose of this document is to provide an overview of the relevant project phases through which the whole project was implemented.

Audience: IT support Team involved in developing the "Solution Portal" area Managers in charge for the various projects they are working on Contributors responsible for managing content Staff users that consume those information and authorized internet visitors

Project Goals: Build the Solutions Portal that it is easy to backup and restore Solutions Portal must have a central Solution Management site where ACME

Managers can easily view the list of current Solutions The Solutions Portal root site will contain a list to help with change management The solution Portal will contain a web part that can clean up unwanted Solutions Each SharePoint solution has its own site, based on a common template Create a dashboard site where users can view information about existing Solutions in

various formats and leveraging SharePoint’s search capability Capture the Developers’ knowledge as they work on SharePoint Projects.

Page 3: SharePoint - ACME Project

ACME Project Phase1

Objectives

Create a new site collection for Acme Inc. Solution Portal, a Solution Site Template and a Developer Knowledge Base. Enable SharePoint features to provide additional functionality to a site collection.

Deliverables

Intranet Portal will be accessible on port 100 using windows authentication and the BI SQL account credentials.

Solution Portal site collection will be accessible on port 100 under the managed path /solutions/ using windows authentication and the BI SQL account credentials. Site will be accessible via the URL http://[server]/solutions.

Solution Portal contains a Developer Knowledge Base wiki. Solution Portal contains a site template to create new Solution sub-sites. Create a SharePoint Group for all Solution Managers. SharePoint features will be enabled to add additional functionality to the Solutions site.

Milestone 1: Configure Farm and Create a New Intranet Website.

Operations: Ensure all out-of-the-box Farm Features are activated. Enable Usage Analysis Processing and Logging. Enable recurring policy usage reports to run every Sunday night at 9pm. Enable Scan documents on upload. Enable Attempt to clean infected documents.

Application Management: Ensure Self-Service Site Creation is turned OFF. Set Search Indexer performance to Reduced.

Configure Shared Service Provider: Enable searching on PDF files Ensure Search Based Alerts are enabled.

Page 4: SharePoint - ACME Project

ACME Project Phase1 (cont)

Set Full Crawl for once a week on Sunday nights. Set Incremental Crawl to every 20 minutes. Start a Full Crawl to populate the index. Ensure user profile import is connected to Active Directory. Schedule incremental import at 2am on the 1st day of each month. Enable advanced usage analysis processing. Enable Search Query Logging.

Create a New Web Application on port 100 with NTLM Authentication.

Set full crawl for once a week on Sunday at 12:00 AM. Set incremental crawl every 20 minutes and start a full crawl to populate the index.

Page 5: SharePoint - ACME Project

ACME Project Phase1 (cont)

Enable Usage Analysis Processing and Logging. Enable recurring policy usage report to run every Sunday at 9:00 AM.

Milestone 2: Create a new Solution site collection

Create a new managed path with explicit inclusion called "Solutions" under the root of the web application on port 100

Create a new quota template called Solution Quota with storage limit of 200 MB and set email alert when 150 MB are reached

Set Site Use Confirmation and Deletion Send e-mail notifications to owners of unused site collections Send notifications 120 days after creation Check for unused site collections monthly Automatically delete the site collection after 5 notices

Create a new Site Collection named Solution Portal for the application on port 100 Use the Blank site template Use site owner credentials for the primary account and BISQL for the secondary one

Page 6: SharePoint - ACME Project

ACME Project Phase1 (cont)

Select the quota previously created This is the Solution Portal that will be referred to in the rest of this documentation

Create a Solution Portal site collection with a Developer Knowledge Base document in it, Solution Site Template sub site with WIKI, calendar and bug tracking (see Milestone 3 below for details).

Milestone 3: Create Developer Knowledge Base

Off the root of the Solution Portal, create a new Wiki Page Library with the name "Developer Knowledge Base"

This will be kept by adding tips, tricks, and information as the development of this project progresses.

Page 7: SharePoint - ACME Project

ACME Project Phase1 (cont)

Activate Office SharePoint Server Publishing Infrastructure, Office SharePoint Web Part and Office SharePoint Standard Site Collection features.

Milestone 4: Create Solution Site Template

Off the root (home page) of the Solution Portal site collection, create new sub site called "Solution Site Template", using the Blank Site Template.

Create the following lists on the Solution Site: Calendar for integration into Outlook. Issues List to track bug and issues that need to be fixed Help Wiki to provide support for end users Announcements List to provide news and information

Save this site as a template in the Site Template Gallery

Page 8: SharePoint - ACME Project

ACME Project Phase1 (cont)

Milestone 5: Create a new Solution Managers Group

Create a new Group in the Solution Portal called Solution Managers and give the members of this group Full Control of this site.

Add at least one user to this group In the Site Collection Settings for the Solutions Portal, turn on the following features:

Office SharePoint Server Publishing Infrastructure Office SharePoint Server Search Web Parts Office SharePoint Server Standard Site Collection Features

Create a new Solution Manager Group and add a user to this group. Give full control to the members of this group.

Page 9: SharePoint - ACME Project

ACME Project Phase2

Objectives

Create custom metadata to track information about a Solution. Setup your development environment to create and deploy SharePoint solutions to your farm. Use Search Web Parts to display helpful information on Solutions elsewhere in the Solution Portal.

Deliverables

Setup the development environment to create and deploy SharePoint solutions to the farm.

Utilize a series of web parts that perform search results or display Solution items in different portions of the site.

Add a Search Results web part to the page that uses a fixed keyword search for items that use the Solution Content Type

Add a Managed Property for the SiteTemplate site column Add a new Search Scope to search on the SiteTemplate site column Add a Keyword and Best Bet to your Site Collection

Milestone 6: Create Solution Content Type

At the root of the Solutions site collection, in the Site Collection Site Settings, create the following site columns: SiteName – Single line of text, required SiteUrl – Hyperlink, required SiteTemplate – Single line of text, optional SiteDescription – Single line of text, optional

Create a new Site Content Type called "Solution" inheriting from List parent and Item content type. Include the four new site columns created above.

Milestone 7: Setup Development Environment

Configure the web.configs to allow debugging and display stack traces Create an environment variable named stsadm on the command line to point to the

stsadm.exe in the 12 hive

Page 10: SharePoint - ACME Project

ACME Project Phase2 (cont)

Install WSPBuilder from CodePlex

Milestone 8: Add a Search Managed Property

Perform a full search crawl - make sure solutions site collection is part of the crawl Create a new Managed Property and select the ows_SiteTemplate element from the

SharePoint group Perform another full crawl Create a fixed keyword custom search box on the Solutions main page so the same

search is always performed

Milestone 9: Add “Saved” Searches to a page

Add Search Core Results webpart to page Modify the web part to add a Fixed Keyword Query: SiteTemplate:Solution

From the Results Query Options area, in the cross-web part query ID dropdown, choose any option except "User Query"

Create a Keyword and Best Bet for the word "Solution"

Milestone 10: Keywords and Best Bets

Add a new Search keyword keyword phrase: solution Synonyms: application;Sharepoint project;proof of concept Add a best bet with the URL: http://[server]/solutions Title: Solution Portal

Do a search for the words "Solution" or "Application" – ensure that the right-hand side best bet appears in the search results page.

Milestone 11: Enable access from the Extranet

Create a FBA database using Visual Studio and add one or more user accounts Extend the Solution web application for extranet users

ACME Project Phase2 (cont)

Page 11: SharePoint - ACME Project

Extend the existing web application using the Extranet Zone Allow extranet users to access it from port 200 Enable Forms Based Authentication by changing the web.config on both the Solution

web application and its extension.

- Turn ON SafeMode CallStack- Add SQL connection string- Set Authentication as Forms

ACME Project Phase2 (cont)

Page 12: SharePoint - ACME Project

Add a user to the database for the form-based authentication through the Web Site Administration Tool.

The extranet (Internet) form-based authentication Login page.

ACME Project Phase3

Page 13: SharePoint - ACME Project

Objectives

Apply a different theme and customize the default Master Page to the Solution site collection. Use Search Web Parts to display helpful information on Solutions elsewhere in the Solution Portal.

Deliverables

Apply a different theme to the Solution site collection Create and deploy a custom Master Page to the Solution site collection Utilize a series of web parts that perform search results or display Solution items in

different portions of the site.

Milestone 8a: Add an Authoring Publishing site

Create a new sub site called "Authoring" as a publishing site (a managed path is required and use Publishing Portal as a site collection template)

Apply a different theme to the publishing site collection. Create a new welcome page based on blank web part template and set it as the default Add 3 functional navigation links with web content editor web part Add a custom search results page

Milestone 9a: Add a Production publishing site

Add a new web application on port 500 based on Blank Site Template Configure web content migration from the authoring site to the production site Complete deployment of the authoring site to production

Milestone 10a: Author New content and quick deploy

Create a new sub site on Authoring with a custom theme named Sales. Add 2 unique Article pages to Sales (need to link those pages to the Sales sub site but

not check them in yet)

ACME Project Phase3 (cont)

Page 14: SharePoint - ACME Project

Create new article page on Authoring site and quick deploy it to production. Verify only the new article page deploys

Deploy the new sales site and verify it succeeds

Create a new welcome page based on blank web part template. Add navigation links list with web content editor web part.

ACME Project Phase3 (cont)

Page 15: SharePoint - ACME Project

ACME Project Phase3 (cont)

Page 16: SharePoint - ACME Project

From the previous picture: Configure web content migration from the authoring development site to production.

Set up a job for the complete deployment of the authoring site to production.

Quick deploy the Authoring site from development to production.

ACME Project Phase3 (cont)

Page 17: SharePoint - ACME Project

This is the customized Welcome page that the production site is accessed from. It is not the default welcome page that SharePoint provides for a site that is being built on the Publishing Template.

ACME Project Phase4

Page 18: SharePoint - ACME Project

Objectives

Change the look and feel of the solution site. Create a new list and a form that managers can use to submit Change Management Requests for a solution. Create a new list to display all the existing Solution sites. Create a web part to view all Solution list items. Create a web part to allow managers to create new SharePoint Solution sites. Create a web part to allow managers to view all Solution sites, and delete those sites.

Deliverables

Apply a different theme to the Solution site collection Create and deploy a custom Master Page to the Solution site collection Change Management List Definition Change Management Request List Change Management Request form in InfoPath that submits to the Change

Management Request List Solution List Definition with event receiver that prevents item deletion Solutions list using this definition, with Solution Content Type applied to it Add a Content Query Web Part to the page that displays all items created using the

Solution content type A custom web part that will create a new SharePoint site under the current site, using a

specified name and a site template chosen from the site’s collection of available Site Templates

A custom web part that will list all the Solution list items, and allow a manager to delete an item. Deleting will remove not only the Solution list item, but the related subsite as well.

Milestone 12: Change Management Request List

Create a new SharePoint List Definition project in Visual Studio named "ChangeManagementListDefinition"

Pick "Form Library" from the Base List Definition dropdown list and ensure that "Add with Event Receiver" is checked

ACME Project Phase4 (cont)

Page 19: SharePoint - ACME Project

Rename the project's ListDefinition1 sub folder to "ChangeManagementListDefinition" In the Schema.xml file, change the Title of the List to "Change Management List

Definition" In ListDefinition.xml, change the Name of the ListTemplate to

"ChangeManagementListDefinition" and DisplayName to "ChangeManagement List Definition"

In the ItemEventReceiver.cs file, rename the class as "ChangeManagementListItemEventReceiver".

In the ListEventReceiver.cs class, change the name of the class to "ChangeManagementListEventReceiver"

Deploy the solution Check in the 12 hive to ensure you have 3 features – for the List Definition, the List

Event receiver, and the Item even receiver Activate the features on the Solutions site collection

o On the Solution Portal root site, create a new list using the Change Management Request List Definition template

Create an instance of the list definition

Milestone 13: InfoPath Change Management Request Form

Design a new Form Template based on the Blank Template. Ensure "Enable browser-compatible features only" is selected. Under Submit Options choose "Allow Users to submit this form" and submit to a SharePoint document library.

The form should contain the following information:o Manager Username (Text)o Manager Full Name (Text)o Request Date (DateTime)o Request Description (Rich Text – Xhtml)

Add a data connection to the Change Management Requests library. Use the path to the Change Management list: http://vm139:100/solutions/Change%20Management%20Request/ . Use Xpath to dynamically populate this name based on the username and date, or on other fields. The goal is to force uniqueness in the file name.

ACME Project Phase4 (cont)

Page 20: SharePoint - ACME Project

Add the following items to the Data Source: Manager User Name (Text), Manager Full Name (Text), Request Date (DateTime), Request Description (Text)

Publish to the SharePoint server Change Management List as a Document Library template (not Site Content Type)

Go back to the Change Management request library and test by creating a new request

Milestone 14: Solution List Definition

Create a new SharePoint List Definition project named "SolutionListDefinition" Pick "Custom List" from the Base List Definition dropdown list and ensure that "Add with

Event Receiver" is checked Rename the project's sub folder from ListDefinition1 to "SolutionListDefinition" In the Schema.xml file, change the Title of the List to "Solution List Definition" In SolutionListDefinition.xml, change the name of the ListTemplate to

"SolutionListDefinition" and DisplayName to "Solution List Definition" In the ItemEventReceiver.cs file, rename the class to "SolutionListItemEventReceiver". Uncomment the following method: "ItemDeleting" Add an error message when the user tries to delete the item, and set the Cancel

property to true to stop the deletion from occurring public override void ItemDeleting(SPItemEventProperties properties) { properties.ErrorMessage = "Solution entries cannot be deleted"; properties.Cancel = true; }

In the ListEventReceiver.cs class, change the name of the class to "SolutionListEventReceiver"

Deploy the solution Check in the 12 hive to ensure you have 3 features – for the List Definition, the List

Event receiver, and the Item event receiver Activate the features on the Solutions site collection On the root of the Solution Portal, create a new Solutions list from the Solution List

Definition. On the Advanced Properties of the Solutions list, allow Manage Content Types. Add the Solution Content Type to the Solutions list as the default

ACME Project Phase4 (cont)

Modify the "All Items" view to show these new columns

Page 21: SharePoint - ACME Project

Add this list’s web part on the site home page Create a Solutions list using this definition Assign the Solution content type "Solution" created in Project 2 to this list

Milestone 15: Content Query Web Parts

Add a content query web part (CQWP) to the Solution home page with the following settings:

o Show items from all sites in this site collectiono Show items from this list type Solution Listo Show items of this content type group Custom Content Typeso Show items of this content type: Solution

Include child content types

Milestone 16: Create Solution Site Web Part

Create a new Web Part SharePoint project in Visual Studio Rename the folder to CreateSolutionSiteWebPart Rename WebPart1.cs to CreateSolutionSiteWebPart Rename WebPart1.webpart to CreateSolutionSiteWebPart.webpart. Change its settings

to match error message, title, and description Rename WebPart1.xml to CreateSolutionSiteWebPart.xml. Modify its xml references to

WebPart1 Add code to display the following components:

o A message indicating success or failure;o Labels and textboxes to allow a user to enter the name of the new site, its

description, and its intended URL;o A dropdown list containing all of the available Site Templates that can be chosen;

remember that the complete list of site templates may include hidden templates which should not be displayed in the dropdown list, so filter them out.

o A button to submit the input.

ACME Project Phase4 (cont)

Page 22: SharePoint - ACME Project

Add an event to handle the click of the Submit button. This method must create a new site using the user’s input

Implement an OnLoad method to call EnsureChildControls() . This will ensure that the Submit button’s event will rise

Add a checkbox to allow Unique Permissions when creating a site. By default this should be set to false – i.e. the site should inherit permissions from its parent. Make sure the web site creation code uses the value of the checkbox

Add a textbox property in the Modify Shared Settings window to allow users to specify the name of the Solution list they are updating. Give it a default name in case the user doesn’t fill in the value. This property makes it easier for you to deploy this web part somewhere else, or change the value if the Solution list name changes for some reason.

Try running the web part as a user without Full Control permissions. If an error is encountered, trap it and display a message.

Add RunWithElevatedPermissions code to the web part so that no matter what permissions the user has, the sub site can be created. Consider the implications of this.

Deploy the web part solution to the farm Activate the Feature on the Solutions site collection Edit the home page of the Solution Portal to add the new web part to it

Milestone 17: Solution Management Web Part

Create a new Web Part SharePoint project in Visual Studio Rename the folder to SolutionManagementSiteWebPart Rename WebPart1.cs to SolutionManagementSiteWebPart. Rename WebPart1.webpart

to SolutionManagementSiteWebPart.webpart. Change its settings to match error message, title, and description with the new class name.

Rename WebPart1.xml to SolutionManagementSiteWebPart.xml. Modify its xml references from WebPart1

Add code to display the following components: a SPGridView displaying all the Solution Items. An instance of DataTable contains all the list items to be displayed.

ACME Project Phase4 (cont)

Page 23: SharePoint - ACME Project

Add an event to handle the click of the Delete button. This method must delete the Solution List item and the sub site, based on information provided from the selected the row.

Add a warning before a user deletes the item Deploy the web part solution to the farm Activate the Feature on the Solutions site collection Edit the home page of the Solution Portal to add the new web part to it.

using System;using System.Runtime.InteropServices;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Serialization;using System.Data;

using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.WebPartPages;

namespace SolutionManagementSiteWebPart{ [Guid("a4f43881-48f1-4c69-9211-793c10d0a5d2")] public class SolutionManagementSiteWebPart : System.Web.UI.WebControls.WebParts.WebPart { private SPGridView sgvItemsListView = null; private DataTable itemsListData = null; private Button btnReturn = null;

// User feedback. private Label lblUserMessage = null;

// Set up the list name to work with. private const string solutionListName = "Solutions";

public SolutionManagementSiteWebPart() { }

protected override void CreateChildControls() { // Supermessage the parent method. base.CreateChildControls();

// Set identifier assigned to the server control. ID = "SolutionManagementSiteWebPart";

ACME Project Phase4 (cont)

Page 24: SharePoint - ACME Project

// Custom rendering. Controls.Add(new LiteralControl( "<table cellpadding='1' border='0'width='100%'><tr><td>")); CreateGridView(); Controls.Add(new LiteralControl("</td></tr>"));

Controls.Add(new LiteralControl("<tr><td>")); btnReturn = new Button(); btnReturn.Text = "Show List Items"; btnReturn.Visible = false; btnReturn.Click += new EventHandler(btnReturn_Click); Controls.Add(btnReturn); Controls.Add(new LiteralControl("</tr></td>"));

Controls.Add(new LiteralControl("<tr><td>")); lblUserMessage = new Label(); Controls.Add(lblUserMessage); Controls.Add(new LiteralControl("</td></tr></table>")); }

protected override void OnPreRender(EventArgs arg) { if (sgvItemsListView != null) PopulateGridView(); }

protected override void OnLoad(EventArgs e) { // Supermessage the parent method. base.OnLoad(e); // Ensure that all the event handlers will be invoked. EnsureChildControls(); }

protected void itemDelete_Click(object sender, GridViewDeleteEventArgs e) { using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = site.OpenWeb()) { try { // Clean user message anyway. lblUserMessage.Text = ""; // Get the datakey of the row being deleted. DataKey key = sgvItemsListView.DataKeys[e.RowIndex];

// Find the url of the site. String url = (String)key.Values["SiteUrl"];

ACME Project Phase4 (cont)

Page 25: SharePoint - ACME Project

url = url.Remove(url.IndexOf("><") - 1); url = url.Remove(0, url.LastIndexOf('/') + 1); // Delete the site. site.AllWebs.Delete(url);

// Delete the matching list item. int listItemID = Int32.Parse(key.Values["ID"].ToString()); SPList solutionsList = web.Lists[solutionListName]; solutionsList.Items.DeleteItemById(listItemID);

// Hide the input controls. sgvItemsListView.Visible = false; // Allow the user to re-activate the grid view. btnReturn.Visible = true; } catch (Exception ex) { lblUserMessage.Text = ex.Message.ToString(); } } } }

protected void itemDelete_AddConfirm(object sender, GridViewRowEventArgs e) { // Apply this only on the expected row type. if (e.Row.RowType == DataControlRowType.DataRow) { // Get the datakey of the row being deleted. DataKey key = sgvItemsListView.DataKeys[e.Row.RowIndex];

// Determine the url to be displayed in the request message. String url = (String)key.Values["SiteUrl"]; url = url.Remove(url.IndexOf("><") - 1); url = url.Remove(0, url.IndexOf('/') - 1); // Attach the JavaScript function showing the requested url. e.Row.Cells[0].Attributes.Add("OnClick", "return confirm('Do you confirm to delete the site: " + url + "?');"); } }

protected void btnReturn_Click(object sender, EventArgs e) { // Go back to the previous page that was sent sent by redirecting // this page to itself. Page.Response.Redirect(SPContext.Current.Web.Url.ToString()); }

ACME Project Phase4 (cont)

Page 26: SharePoint - ACME Project

private void CreateGridView() { sgvItemsListView = new SPGridView(); sgvItemsListView.AutoGenerateColumns = false; sgvItemsListView.AutoGenerateDeleteButton = true; sgvItemsListView.Width = Unit.Percentage(100); Controls.Add(sgvItemsListView);

sgvItemsListView.RowDeleting += new GridViewDeleteEventHandler(itemDelete_Click); sgvItemsListView.RowDataBound += new GridViewRowEventHandler(itemDelete_AddConfirm);

BoundField colTitle = new BoundField(); colTitle.DataField = "Title"; colTitle.HeaderText = "Title"; sgvItemsListView.Columns.Add(colTitle);

BoundField colSiteName = new BoundField(); colSiteName.DataField = "SiteName"; colSiteName.HeaderText = "Site Name"; sgvItemsListView.Columns.Add(colSiteName);

BoundField colSiteDescription = new BoundField(); colSiteDescription.DataField = "SiteDescription"; colSiteDescription.HeaderText = "Site Description"; sgvItemsListView.Columns.Add(colSiteDescription);

BoundField colSiteTemplate = new BoundField(); colSiteTemplate.DataField = "SiteTemplate"; colSiteTemplate.HeaderText = "Site Template"; sgvItemsListView.Columns.Add(colSiteTemplate);

HyperLinkField colSiteUrl = new HyperLinkField(); colSiteUrl.DataTextField = "SiteUrl"; colSiteUrl.DataNavigateUrlFields = new string[] { colSiteUrl.DataTextField }; colSiteUrl.HeaderText = "Site Url"; sgvItemsListView.Columns.Add(colSiteUrl); }

void PopulateGridView() { try { // Do NOT dispose, it causes run time error on the requested // page! SPWeb web = SPContext.Current.Web; SPList list = web.Lists[solutionListName];

itemsListData = new DataTable();

ACME Project Phase4 (cont)

Page 27: SharePoint - ACME Project

itemsListData.Columns.Add("ID"); itemsListData.Columns.Add("Title"); itemsListData.Columns.Add("SiteName"); itemsListData.Columns.Add("SiteDescription"); itemsListData.Columns.Add("SiteTemplate"); itemsListData.Columns.Add("SiteUrl");

foreach (SPListItem item in list.Items) { DataRow row = itemsListData.NewRow(); row["ID"] = item["ID"].ToString(); row["Title"] = item["Title"] == null ? "" : item["Title"].ToString(); row["SiteName"] = item["SiteName"] == null ? "" : item["SiteName"].ToString(); row["SiteDescription"] = item["SiteDescription"] ==null? "" : item["SiteDescription"].ToString(); row["SiteTemplate"] = item["SiteTemplate"] == null ? "" : item["SiteTemplate"].ToString(); row["SiteUrl"] = item["SiteUrl"] == null ? "" : item["SiteUrl"].ToString(); itemsListData.Rows.Add(row); } sgvItemsListView.DataKeyNames = new string[] { "ID", "SiteUrl" }; sgvItemsListView.DataSource = itemsListData; sgvItemsListView.DataBind(); } catch (Exception e) { lblUserMessage.Text = e.Message; } } }}

The code shown above is the content of SolutionManagementSiteWebPart.cs, which defines the SolutionManagementSiteWebPart class according to the requirements for this milestone.

ACME Project Phase4 (cont)

Page 28: SharePoint - ACME Project

This is how the Solution site looks like at the completion of Milestone 17. Notice the custom web part to add a new site to the home site and the lists, below and above it, to track the sites that have been created.

ACME Project Phase5

Page 29: SharePoint - ACME Project

Objectives

Create a Search Center. Modify the Advanced Search page to search by the SiteTemplate column. Create a web part to allow users to run custom Keyword search queries and view the results. Modify the Search Results output to show the raw search results. Deploy an Excel Services spreadsheet to report on Solution metrics. Create a new KPI list to use KPIs against the Excel Services spreadsheet.

Deliverables

Create a Search Center where you can modify Search Results. A custom web part that allows a user to enter a keyword query into a textbox, and

display the query results in a grid. Modify the search results output XSL to show the raw search results

Milestone 18: Search Center with Managed Property Search

Create a new Search Center with Tabs site called Search. Edit the Advanced Search page – modify Advanced Search Box Add a new PropertyDef element for the SiteTemplate managed property Under ResultType "All Results" add a new PropertyRef element for SiteTemplate Show the scope picker Hide the Languages picker

Milestone 19: Site Collection Search Settings and Scopes

In site collection settings, under search settings: choose use custom scopes. Set the search page to be : /solutions/search/Pages/

In Site Collection settings, create a new Search Scope Give it the name "Only Sites Created using Solution Site Templates" Choose both advanced and dropdown for appearance

ACME Project Phase5 (cont)

Page 30: SharePoint - ACME Project

Add a rule - property query - choose SiteTemplate from dropdown list = "Solution Site Template". Make it required

Wait about the scheduled time until the scope is updated, in the search dropdown now see the new scope

The search results will only display solution content types whose site template value is equal to Solution Site Template

Milestone 20: Custom Search Web Part

Create a custom web part to make custom keyword search queries. The web part should:

o Allow the user to enter query texto Execute a Keyword query on the Search engineo Show a grid view with all the Search results bound to its data source

In the web part project, reference the SharePoint Search dll - kept in microsoft.sharepoint.search.dll (12 hive \isapi folder).

Assign an indexer to the content database:o From Central admin select: Application Management and click Content databases under

the "SharePoint Web Application Management" headero Set the application to http://vm139:100/o Select the existing content database used by the site to open the " Manage Content

Database Settings" pageo In the " Manage Content Database Settings" page, Select VM139 in the "Select Windows

SharePoint Services search server" dropdown list within the "Search Server" section Write code that will display a textbox input as a keyword search query in a grid view.

The grid view will be rendered only if valid data from the query have been extracted. Execute the search query and bind to the grid’s data source Add controls to display the number of results and to limit the maximum number of

results returnedo Details for the previous bulleted points are found in CreateCildControls() and

btnSearch_Click() methods of the CustomSearchWebPart class as depicted belowo The code reports only the number of records being extracted

ACME Project Phase5 (cont)

Page 31: SharePoint - ACME Project

using System;using System.Runtime.InteropServices;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Serialization;using System.Data;

using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using Microsoft.SharePoint.WebPartPages;using Microsoft.Office.Server;using Microsoft.Office.Server.Search.Query;using Microsoft.Office.Server.Search.Administration;

namespace CustomSearchWebPart{ [Guid("e9f4bd0c-b939-4049-b650-2e5289ebae14")] public class CustomSearchWebPart : System.Web.UI.WebControls.WebParts.WebPart { // User feedback on the operation. private Label lblMessage = null;

private Label lblSearchKeyword = null; private TextBox tbxSearchKeyword = null; private Button btnSearch = null; private SPGridView sgvQueryResult = null; private DataTable resultsTable = null;

public CustomSearchWebPart() { }

protected override void CreateChildControls() { // Supermessage the parent method. base.CreateChildControls();

// Custom rendering. Grid view will be rendered if data is // available. Controls.Add(new LiteralControl( "<br /><table><tr><td colspan='3'>")); lblMessage = new Label(); Controls.Add(lblMessage); Controls.Add(new LiteralControl("</td></tr>"));

Controls.Add(new LiteralControl("<tr><td>")); lblSearchKeyword = new Label(); lblSearchKeyword.Text = "Search Keyword "; Controls.Add(lblSearchKeyword);

ACME Project Phase5 (cont)

Page 32: SharePoint - ACME Project

Controls.Add(new LiteralControl("</td><td>")); tbxSearchKeyword = new TextBox(); Controls.Add(tbxSearchKeyword);

Controls.Add(new LiteralControl("</td><td>")); btnSearch = new Button(); btnSearch.Text = " Search "; btnSearch.Click += new EventHandler(btnSearch_Click); Controls.Add(btnSearch); Controls.Add(new LiteralControl("</td></tr></table><br />")); }

protected override void OnLoad(EventArgs e) { // Supermessage the parent method. base.OnLoad(e); // Ensure that all the event handlers will be invoked. EnsureChildControls(); }

protected void btnSearch_Click(object sender, EventArgs e) { // Create the query instance. ServerContext serverContext = ServerContext.GetContext("SharedServices1"); KeywordQuery query = new KeywordQuery(serverContext);

try { // Specify the query and result type. query.QueryText = tbxSearchKeyword.Text; ResultType resultType = ResultType.RelevantResults; query.ResultTypes = resultType;

// Execute the query. ResultTableCollection results = query.Execute();

// Display results in the grid only if they were found. if (results.Exists(resultType)) { resultsTable = new DataTable(); resultsTable.Load(results[resultType], LoadOption.OverwriteChanges);

if (resultsTable.Rows.Count > 0) { // Render grid view with the results. sgvQueryResult = new SPGridView(); sgvQueryResult.AutoGenerateColumns = false; sgvQueryResult.Width = Unit.Percentage(100);

ACME Project Phase5 (cont)

Page 33: SharePoint - ACME Project

SPBoundField colRank = new SPBoundField(); colRank.DataField = "Rank"; colRank.HeaderText = "Rank"; sgvQueryResult.Columns.Add(colRank);

HyperLinkField colTitle = new HyperLinkField(); colTitle.HeaderText = "Title"; colTitle.DataTextField = "Title"; colTitle.DataNavigateUrlFields = new string[] { "Path" }; colTitle.DataNavigateUrlFormatString = "{0}"; sgvQueryResult.Columns.Add(colTitle);

SPBoundField colAuthor = new SPBoundField(); colAuthor.DataField = "Author"; colAuthor.HeaderText = "Author"; sgvQueryResult.Columns.Add(colAuthor);

SPBoundField colWrite = new SPBoundField(); colWrite.DataField = "Write"; colWrite.HeaderText = "Date Created"; sgvQueryResult.Columns.Add(colWrite);

SPBoundField colSize = new SPBoundField(); colSize.DataField = "Size"; colSize.HeaderText = "Size"; sgvQueryResult.Columns.Add(colSize);

SPBoundField colDescription = new SPBoundField(); colDescription.DataField = "Description"; colDescription.HeaderText = "Description"; sgvQueryResult.Columns.Add(colDescription);

sgvQueryResult.DataSource = resultsTable; sgvQueryResult.DataBind(); Controls.Add(sgvQueryResult);

lblMessage.Text = "<div style='color:blue;" + " font-weight:bold'>Your search returned " + sgvQueryResult.Rows.Count.ToString()" + "record(s).</div>"; } else { lblMessage.Text = "<div style='color:red; font-weight:bold'>" + "No results matching your search were found." + "</div>"; }

ACME Project Phase5 (cont)

Page 34: SharePoint - ACME Project

} else { lblMessage.Text = "<div style='color:red; font-weight:bold'>" + "No results matching your search were found.</div>"; }

// Prompt the user for a spelling suggestion. if (results.SpellingSuggestion != string.Empty) { lblMessage.Text = string.Format( "<div>Did you mean? {0}</div>", results.SpellingSuggestion); } } catch (Exception ex) { lblMessage.Text = "<div style='color:red; font-weight:bold'>" + ex.Message + "</div>"; } } }}

The code shown above is the content of CustomSearchWebPart.cs, which defines the CustomSearchWebPart class according to the requirements for this milestone.

ACME Project Phase5 (cont)

Page 35: SharePoint - ACME Project

This shows a custom key search which shows that 3 records were found.

This is how the Solution site looks like at the completion of Milestone 17. Notice the custom web part to perform the key search. A grid view is shown under the input edit box and Search button only if there are available records.