Posts

Showing posts from July, 2013

Update Managed Metadata Field in SharePoint 2013

The following example update a term store field that allow multiple values. using (SPSite site = new SPSite("siteUrl"))                 {                     using (SPWeb web = site.OpenWeb())                     {                         PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);                         PublishingPageCollection pubPages = pubWeb.GetPublishingPages();                         string metadata = String.Empty;                         foreach (PublishingPage pubPage in pubPages)                         {   ...

Update people field

The following code sample add a new member to the SharePoint 2013 Community Site Member list.  It update the "Member" field. using (SPSite site = new SPSite("http://siteurl/"))                 {                     using (SPWeb web = site.OpenWeb())                     {                         SPList members = web.Lists.TryGetList("Community Members");                         SPListItem newMember = members.AddItem();                                               SPUser ensuredUser2 = web.EnsureUser("domain\\loginName");                       ...

Create Custom Content by Search Web Part

This is an example of appending additional query to the one that is in the query builder.  You can based on this one and build more complicated logic to alter your query on the fly. using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.Office.Server.Search.WebControls; using System.Collections.Generic; using SWP = Microsoft.SharePoint.WebPartPages; using Microsoft.SharePoint.WebPartPages; public class CustomContentSearchWebPart : ContentBySearchWebPart     { private string  additionalQuery = String .Empty;         [ WebBrowsable ( true ),          WebDisplayName ( "Additional Query" ),          WebDescription ( "Additional query for web part to ins...