Thursday, June 27, 2013

How to get Search Service Applications Programmatically

Leave a Comment
Today i came across scenario, where i need to get programmatically list of Service Service Applications in the farm.

Below code snippet will show search service applications in the farm.


using System.Linq;
using Microsoft.SharePoint.Administration;

namespace SearchApplications
{
    internal class Program
    {
        private static void Main(string[] args)
        {
 
                           var farm = SPFarm.Local;
                           var service = farm.Services.OfType<SearchQueryAndSiteSettingsService>().First();
                           var applications = service.Applications.ToList();

                           foreach (var app in applications)
                           {
                                Console.WriteLine(app.Name);
                           }  
        }
    }
}


Read More...

Sunday, June 16, 2013

Add custom section in Site Settings

Leave a Comment
Step by step guide to show custom action section in site settings page.  After deploying solution, we will see following settings in site settings page.


To start with go to File à New à Project à SharePoint 2013 – Empty Project
Add application page to the project by right clicking to project à Add à New Item à Application Page (Farm Solution Only)
This will add Layouts mapping Folder to the project. Update Folder name to “HandsOn”.

Then Add empty Element to the project.  Remove sample.txt file from the module.
Open elements.xml file and add CustomActionGroup and CustomAction to the file.


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomActionGroup
     Id="MyConfigurationGroup"
     Location="Microsoft.SharePoint.SiteSettings" 
     Title="Custom Configuration"
     Sequence="1" 
     Description="My configuration section"
     ImageUrl="/_layouts/Images/STSICON.GIF" 
    />

  <CustomAction
    Id="MyConfigPage1"
    GroupId="MyConfigurationGroup"
    Location="Microsoft.SharePoint.SiteSettings"
    Description="My Config page"
    Title="My Configuration"
    Rights="MangeWeb"
    ImageUrl="/_layouts/Images/STSICON.GIF">
    <UrlAction Url="~site/_layouts/HandsOn/MyConfiguration.aspx"/>
  </CustomAction>
</Elements>
 



Package and deploy solution.

After deployment, site settings will have new section with name “Custom Configuration” and “My Configuration” item. On clicking “My Configuration” you will be redirected to MyConfiguration.aspx page.



Read More...