Sharepoint 2010 Books
Getting Started, Administration, Development , Customization, Office 2010 Integration , Collaboration and many other subjects to save you time and efforts and help you make the most of the platform.
Getting Started, Administration, Development , Customization, Office 2010 Integration , Collaboration and many other subjects to save you time and efforts and help you make the most of the platform.
SharePoint – Hide actions menu items : A SharePoint solution allowing you to easily hide/show menu items from the Actions menu such as the datasheet view
SharePoint – SPForms Designer : A SharePoint solution allowing you to easily customize the new/edit/display forms associated with lists.
SharePoint Tool Basket MOSS Solution : all the solutions described below + the rating system packaged into a single solution. Do not install it if you have already installed one of the below solutions previously because the solution deployment would fail. If you want to install it, first remove any previsouly installed solution of the below list.
SharePoint – SPFeature Explorer : A windows application allowing developers to easily identify all the features installed in the farm and where they are active.
SharePoint – SPContentType Explorer : A SharePoint application page that's very similar to the standard content type pages but that allows you to see where a content type is used accross an entire site collection
SharePoint – Autocomplete lookup field with AJAX : An AJAX-Enabled SharePoint custom lookup field allowing users to benefit from the advantages of standard lookup fields with the rapidity of AJAX. Note that this solution doesn't require the AJAX extensions nor the .NET framework 3.5 to work. It works on both WSS & MOSS pre and post SP1
SharePoint – List Columns Manager : A SharePoint feature allowing site collection administrators to manage the columns of a list (set them in read-only, hide them, set them visible/invisible in the edit/new/display forms) and to visualize the list's associated event handlers and the CAML of each associated view
SharePoint – Audience to Groups convertor : A SharePoint webpart allowing site collection administrators to create SharePoint groups based on SharePoint audiences and to maintain an automatic synchronization .
http://www.codeplex.com/SharePointPSScripts/ : A set of useful PowerShell scripts that make life of IT & Developers easier
protected override void CreateChildControls()
{
SPWeb thisWeb = SPContext.Current.Web;
SPList tasks = thisWeb.Lists["Tasks"];
ListViewByQuery listTasks = new ListViewByQuery();
listTasks.List = tasks;
SPQuery taskQuery = new SPQuery(listTasks.List.DefaultView);
taskQuery.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='Due' />";
taskQuery.Query = "<Where><Leq><FieldRef Name='Due' /><Value Type='DateTime'>"
+ SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now.AddMonths(1))
+ "</Value></Leq></Where>";
listTasks.Query = taskQuery;
this.Controls.Add(listTasks);
base.CreateChildControls();
}
The following code shows how to extract the selected people in a PeopleEditor control.
Note: The code runs in a Visual Web Part, and relies on there being a PeopleEditor control named peoplePicker, and an ASP.NET ListBox control called selectedPeople
namespace SharePointControls.ControlExample
{
public partial class ControlExampleUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void getPeople(object sender, EventArgs e)
{
string allPeople = peoplePicker.CommaSeparatedAccounts;
string[] selected = allPeople.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string p in selected)
{
selectedPeople.Items.Add(p);
}
}
}
}
The following code shows how to use the SPGridView control in a Web Part to display list items from a list:
protected override void CreateChildControls()
{
SPGridView taskGrid = new SPGridView();
taskGrid.AutoGenerateColumns = false;
BoundField taskTitle = new BoundField();
taskTitle.DataField = "Title";
taskTitle.HeaderText = "To Do…";
taskGrid.Columns.Add(taskTitle);
SPWeb thisWeb = SPControl.GetContextWeb(Context);
SPList taskList = thisWeb.Lists["Tasks"];
SPDataSource listSource = new SPDataSource();
listSource.List = taskList;
SPDataSourceView view = listSource.GetView();
taskGrid.DataSource = listSource;
if (view.CanSort)
{
taskGrid.AllowSorting = true;
}
taskGrid.DataBind();
Controls.Add(taskGrid);
base.CreateChildControls();
}
namespace ProductMarketing.ProductTaskEvents
{
public class ProductTaskEvents : SPListEventReceiver
{
public override void FieldAdded(SPListEventProperties properties)
{
SPField newField = properties.Field;
Guid fieldID = newField.Id;
if (newField.Type == SPFieldType.Text)
{
SPList thisList = properties.List;
foreach (SPListItem item in thisList.Items)
{
item[fieldID] = "Please update this existing item…";
item.Update();
}
}
base.FieldAdded(properties);
}
public override void ListDeleting(SPListEventProperties properties)
{
properties.ErrorMessage = "This list is critical to the marketing campaign and cannot be deleted.";
properties.Cancel = true;
}
}
}
The following event handler shows how to update properties of a SharePoint Web site when a new Web is created
namespace ProductMarketing.ProductMarketingWebEvents
{
public class ProductMarketingWebEvents : SPWebEventReceiver
{
public override void WebProvisioned(SPWebEventProperties properties)
{
SPWeb thisNewWeb = properties.Web;
thisNewWeb.AllowUnsafeUpdates = true;
thisNewWeb.Title = "Updated in Code";
thisNewWeb.Update();
thisNewWeb.AllowUnsafeUpdates = false;
base.WebProvisioned(properties);
}
}
}
The following code shows how to enumerate the alerts in a SharePoint site, and also how to enable or disable alerts.
Note: This code is designed to run on an application page that includes:
– An ASP.NET Label control called alertCount
– An ASP.NET button that includes a Click event handler set to the EnableAll funtion
– An ASP.NET button that includes a Click event handler set to the DisableAll funtion
namespace Alerter.Layouts.Alerter
{
public partial class Alerts : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
int enabled = 0;
int disabled = 0;
SPWeb thisWeb = SPContext.Current.Web;
foreach (SPAlert alrt in thisWeb.Alerts)
{
if (alrt.Status == SPAlertStatus.On)
{
enabled++;
}
if (alrt.Status == SPAlertStatus.Off)
{
disabled++;
}
}
alertCount.Text = "Enabled Alerts: " + enabled.ToString()
+ "\nDisabled Alerts" + disabled.ToString();
}
protected void EnableAll(object sender, EventArgs e)
{
SPWeb thisWeb = SPContext.Current.Web;
foreach (SPAlert alrt in thisWeb.Alerts)
{
alrt.Status = SPAlertStatus.On;
alrt.Update();
}
}
protected void DisableAll(object sender, EventArgs e)
{
SPWeb thisWeb = SPContext.Current.Web;
foreach (SPAlert alrt in thisWeb.Alerts)
{
alrt.Status = SPAlertStatus.Off;
alrt.Update();
}
}
}
}
The following code creates a new SharePoint site (SPWeb object):
SPSite thisSite = SPContext.Current.Site;
thisSite.RootWeb.AllowUnsafeUpdates = true;
SPWeb hrWeb = thisSite.RootWeb.Webs.Add("HRWeb",
"Human Resources Web",
"For use by HR Employees",
1033,
"STS#0",
false,
false);
hrWeb.Dispose();
thisSite.RootWeb.AllowUnsafeUpdates = false;
The following code enumerates all of the services provided by the current farm's SPFarm object and displays them in a treeview control in an application page.
Note: The code relies on there being a tree-view named farmContents in the application page.
namespace Hierarchy.Layouts.Hierarchy
{
public partial class HierarchyViewer : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPFarm thisFarm = SPFarm.Local;
TreeNode node;
farmContent s.Nodes.Clear();
foreach(SPService svc in thisFarm.Services)
{
node = new TreeNode();
node.Text = "(Type=" + svc.TypeName + ") " + svc.DisplayName;
farmContents.Nodes.Add(node);
}
farmContents.CollapeAll();
}
}
The following code enumerates all of the services, web applications, site collections, sites, and lists in a SharePoint farm, and displays them in a treeview control in an application page.
Note: The code relies on there being a tree-view named farmContents in the application page. Also note how the addWebs() function is called recursively to ensure sites and subsites are enumerated and displyed in the treeview.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.Administration;
namespace Hierarchy.Layouts.Hierarchy
{
public partial class HierarchyViewer : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPFarm thisFarm = SPFarm.Local;
TreeNode node;
farmContents .Nodes.Clear();
foreach(SPService svc in thisFarm.Services)
{
node = new TreeNode();
node.Text = "(Type=" + svc.TypeName + ") " + svc.DisplayName;
farmContents.Nodes.Add(node);
TreeNode svcNode = node;
if (svc is SPWebService)
{
SPWebService webSvc = (SPWebService)svc;
foreach (SPWebApplication webApp in webSvc.WebApplications)
{
node = new TreeNode();
node.Text = webApp.DisplayName;
svcNode.ChildNodes.Add(node);
TreeNode webAppNode = node;
foreach (SPSite site in webApp.Sites)
{
try {
node = new TreeNode();
node.Text = site.Url;
webAppNode.ChildNodes.Add(node);
TreeNode siteNode = node;
site.CatchAccessDeniedException = false;
try
{
node = new TreeNode(site.RootWeb.Title, null, null, site.RootWeb.Url, "_self");
siteNode.ChildNodes.Add(node);
TreeNode parentNode = node;
foreach (SPList list in site.RootWeb.Lists)
{
node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self");
parentNode.ChildNodes.Add(node);
}
foreach (SPWeb childWeb in site.RootWeb.Webs)
{
try {
addWebs(childWeb, parentNode);
} finally
{
childWeb.Dispose();
}
}
}
catch
{ }
}
finally
{
site.Dispose();
}
}
}
}
}
farmContents.CollapseAll();
}
void addWebs(SPWeb web, TreeNode parentNode)
{
TreeNode node;
node = new TreeNode(web.Title, null, null, web.Url, "_self");
parentNode.ChildNodes.Add(node);
parentNode = node;
foreach (SPList list in web.Lists)
{
node = new TreeNode(list.Title, null, null, list.DefaultViewUrl, "_self");
parentNode.ChildNodes.Add(node);
}
foreach (SPWeb childWeb in web.Webs)
{
try {
addWebs(childWeb, parentNode);
} finally {
childWeb.Dispose();
}
}
}
}
}