Posts Tagged ‘Microsoft SharePoint’

How to rebuild Search Service Application in SharePoint 2010

May 31, 2012 3 comments

1) Open SharePoint Management Shell as an administrator


Delete the Search Service Application


2) Locate the GUID for the search service application by typing


Get-SPServiceApplication |?{$ -eq “<name of the search application>”}


3) Copy the names of the Databases associated with the Search Service Application

4) Run the following stsadm command


Stsadm.exe –o deleteconfigurationobject –id ‘<GUID>’

4 ) Delete the following databases from SQLManagementStudio . The exact names are copied under Step 3.





5) Delete the index files from Program Files\Microsoft Office Servers\14\Data\Office Servers\Applications


6) Go to Central AdministrationàManage Service Applications

7) Click New Search Service Application

8) Provide a name to the application and select the managed account and Click Ok

Wait for the confirmation

Configure the new Search Service Application


9) Add the existing portal address in the content sources and setup Full Crawl and Incremental crawl.

10) Run full crawl






Create a list in all the sites using Powershell

September 20, 2011 3 comments

Here is way to create a list based on a custom template using Powershell. The script will go through each site and create the list and add them to the Quick Launch

$GetSites = Get-SPWebApplication | Get-SPSite | Get-SPWeb -Limit ALL
foreach($getsite in $GetSites)
$listTemplate = $getsite.Site.GetCustomListTemplates($getsite)
$getsite.Lists.Add("MyList","My List",$listTemplate["MyTemplate"])
$list = $getsite.Lists["MyList"]
$list.OnQuickLaunch = $true


Make sure that custom template is uploaded in the List Template Gallery. Check out this link  if you want to add a list template using powershell

Copy value from column to another using JQuery

August 19, 2011 1 comment

Copy the value from one column to another column on a New List Item Form.

In this example, I am populating the End Date Field with the Start Date Field value when user is filling out a meeting request form in SharePoint.

Add the following code on the page under “PlaceHolderMain” tag.

<script type="text/javascript" src="../../Shared Documents/Javascript/jquery/jquery.js">

var strStartDate = $("input[title='Start Date']");
$("input[title='End Date']").val(strStartDate.val());

How to create Views Programmatically in SharePoint 2010

August 17, 2011 2 comments

Below is the code snippet to create views programmatically

Create a View

      private void CreateView(string strViewName)
string fieldName = //Get Field Internal Name
var docquery = "<Where><Eq><FieldRef Name='" + fieldName.ToString() + "' /><Value Type='Choice'>" + strViewName.ToString() + "</Value></Eq></Where>";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Modified By");
oViewCollection.Add(strViewName, viewFields, docquery, 100, true, false);
catch (Exception e)
throw new SPException(e.Message.ToString());

You can use U2U Query Builder tool to build CAML query (


Comments History not showing on Custom Display Form

April 4, 2011 2 comments

Creating Custom Display Form in SharePoint Designer for a List does not show history for Comments field by default.
Here is the fix for that:


<xsl: select=”@V3Comments” value-of disable-output-escaping=”yes”  />


<SharePoint:AppendOnlyHistory runat=”server” ControlMode=”Display” FieldName=”V3Comments” ItemId=”{@ID}”  />

This should fix the issue and start showing all the comments added in the Comments Field.

How to add and remove entries from Web.Config using SPWebConfigModification

March 3, 2011 3 comments

Often times during SharePoint Development , we need to store configuration related entries in the web.config file. We can use Property Bag tool from CodePlex but in case you would like to use a Feature

then here are the steps to create a Feature that will add entries to the web.config for the SharePoint Web Application.

  • Open Visual Studio 2010
  • Select New à Project à Empty SharePoint Project
  • Provide a local site and Select “Deploy as a farm solution” option.


  • Right Click on the “Features” and Select “Add Feature”


  • On the following screen, provide the Unique Title Name and Description. (Refer to screen below) .

    (Mostly developers don’t put anything in Description but this information really comes in handy when you are trying to figure out what is a specific Feature suppose to do in terms of functionality)

  • Right Click on Feature1.Feature and Click on “Add Event Receiver”



  • Uncomment the “Feature Activated” part of the code






  • Add the following Code in FeatureActivated Method

This code is adding the following entries in web.config

  1. Connection Strings
  2. Key Value pair in AppSettings section

For each child node entry provide a specific owner name (like “Smartrider” in my case).We will need this as a reference later on in case you want to remove the entries (we are going to do this during Deactivation)


string value = @”Test”

SPWebApplication webApp = SPWebApplication.Lookup(new

SPWebService service = SPWebService.ContentService;

SPWebConfigModification connMod = new

connMod.Path = “configuration”;

connMod.Name = “connectionStrings”;

connMod.Value = ” <connectionStrings> </connectionStrings>”;

connMod.Owner = Assembly.GetExecutingAssembly().FullName;

connMod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection;



//SQL Connetion String

SPWebConfigModification webConfigMod = new

webConfigMod.Owner = “Smartrider”;

webConfigMod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;

webConfigMod.Value = String.Format(“<add name=\”{0}\” connectionString=\”{1}\” providerName=\”{2}\”></add>”, “conn”, “Data Source=<datasource>;Initial Catalog=<databasename>;Integrated Security=True”, “System.Data.SQLClient”);

webConfigMod.Path = “configuration/connectionStrings”;

webConfigMod.Name = “sqlConn”;


//Add NetworkShare URL

SPWebConfigModification appConfigMod = new

appConfigMod.Owner = “Smartrider”

appConfigMod.Path = “configuration/appSettings”;

appConfigMod.Name = String.Format(“add [@key=’NetworkURL’] [@value='{0}’]”, value);

appConfigMod.Value = String.Format(“<add key=’NetworkURL’ value='{0}’ />”, value);

appConfigMod.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode;




  • You also want to add code to remove the entry when the Feature is Deactivated. One way to do find all the entries that are inserted by Owner name “Smartrider”.


void FeatureDeactivating(SPFeatureReceiverProperties properties)


SPWebApplication webApp = SPWebApplication.Lookup(new








catch (Exception ex)


throw ex;



//Remove Entries made to web.config by Owner name “Smartrider”

void RemoveEntries(SPWebApplication webApp)




List<SPWebConfigModification> entriesToRemove = new

foreach(SPWebConfigModification configMod in webApp.WebConfigModifications)


if(configMod.Owner == “Smartrider”)





if(entriesToRemove.Count > 0)


for (int i = entriesToRemove.Count – 1; i >= 0; i–)











  • Deploy the code and check the web.config file to verify your entries.
  • Done