Search This Blog

Wednesday, March 30, 2016

How to enable custom login page in SharePoint 2013

1. Enable anonymous for that web application

    1.1 Choose your web application
   

    1.2 Choose the Authentication Providers from top menu

  

    1.3 From that check the Enable anonymous access
2. Enable Forms Based Authentication (FBA)
   ASP.NET Membership provider name - wmembership
   ASP.NET Role manager name - wrolemanager
 

3. Change the Custom login page url in you webconfig. In authentication tab change the default URL
   <forms loginUrl="/_layouts/15/CustomLogin/Login.aspx" domain="domain.com" />
 
4. Add the following tag in Security token config file

<system.web>
    <membership defaultProvider="wmembership">
      <providers>
        <add name="wmembership" type="Nauplius.ADLDS.Provider.LdapMembership, Nauplius.ADLDS.Provider.2013, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e1247d213b5ddc40" server="trigchn.com" port="389" useSSL="false" userDNAttribute="distinguishedName" userNameAttribute="sAMAccountName" userContainer="DC=trigchn,DC=com" userObjectClass="person" userFilter="(ObjectClass=person)" scope="Subtree" otherRequiredUserAttributes="sn,givenname,cn" />
      </providers>
    </membership>
    <roleManager defaultProvider="wrolemanager" enabled="true" cacheRolesInCookie="true" cookieName=".PeopleDCRole">
      <providers>
        <add name="wrolemanager" type="Nauplius.ADLDS.Provider.LdapMembership, Nauplius.ADLDS.Provider.2013, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e1247d213b5ddc40" server="trigchn.com" port="389" useSSL="false" groupContainer="DC=trigchn,DC=com" groupNameAttribute="cn" groupNameAlternateSearchAttribute="samAccountName" groupMemberAttribute="member" userNameAttribute="sAMAccountName" dnAttribute="distinguishedName" groupFilter="((ObjectClass=group)" userFilter="((ObjectClass=person)" scope="Subtree" />
      </providers>
    </roleManager>
  </system.web>

5. Now do an IISREST and refresh your application. You can see your custom login page.
  

Wednesday, March 23, 2016

Creating SharePoint Timer Job

Timer Job:

Timer Job is a background process that are run by SharePoint. It is a periodically executed task inside SharePoint Server. It provides us a task execution environment.


Default Timer Jobs inside SharePoint:

There are many timer jobs inside SharePoint which do internal tasks like:
    • Send emails
    • Validate sites
    • Delete unused sites
    • Health analysis
    • Product versioning
    • Diagnostics
These tasks will having execution periods like:
    • Minute
    • Hour
    • Day
    • Week
    • Month

1) Create an empty SharePoint project and add an class file in that project.
    Derive CustomTimerJob Class from SPJobDefinition which comes from 
    Microsoft.SharePoint.Administration.dll

Example:
    class TestTimerJob : SPJobDefinition
    {
     }

2) Add the three Constructors of the derived class : When ever we create the object of CustomTimerJob  class, corresponding constructor will execute.
   
Example:  
  public TestTimerJob() : base()
        {
        }

   public TestTimerJob(string sJobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(sJobName, service, server, targetType)
        {
        }

   public TestTimerJob (string sJobName, SPWebApplication webApplication)
            : base(sJobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "Test Time Job";
        }

3) Override the Execute method: When ever the timer job start running then the code inside the Execute method will run.

Example: 


public override void Execute(Guid targetInstanceId)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite Osite = new SPSite(SPContext.Current.Site.ID))
                    {
                        using (SPWeb Oweb = Osite.OpenWeb())
                        {
                            SPList TestTasksList = Oweb.Lists.TryGetList("TestTasksList ");                          
                            SPListItemCollection TestTasksListCol = TestTasksList.GetItems();
                            foreach(SPListItem Oitem in TestTasksListCol)
                           {       
                                 Oitem["Title"]="TimerJob";
                                  Oitem.Update();   
                           }
                        }
                    }
                });
            }
            catch (Exception)
            {
                throw;
            }
        }


4) We need to create a Feature and Feature Receiver so on activation of this feature we are going the add our timer job to SharePoint farm.
    1. Create a new feature and set its scope as Site
    2. Add an event receiver by right clicking that feature. 
    3. And also create a name for your timer job;

const string JOB_NAME = "Test TimerJob";

       In that feature include the following code for Feature activated and Feature Deactivating

Feature Activated:
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == JOB_NAME)
                    job.Delete();
            }
            OverdueTasksTimerJob listLoggerJob = new OverdueTasksTimerJob(JOB_NAME, site.WebApplication);
            //SPMinuteSchedule schedule = new SPMinuteSchedule();
            SPDailySchedule schedule = new SPDailySchedule();
            schedule.BeginSecond = 0;
            schedule.EndSecond = 59;
            //schedule.Interval = 5;
            listLoggerJob.Schedule = schedule;
            listLoggerJob.Update();
        }

Feature Deactivated:
       public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPSite site = properties.Feature.Parent as SPSite;

            // Delete the timer job
            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == JOB_NAME)
                    job.Delete();
            }
        }

5) Next deploy you solution and check you timer job is comes under Job definitions in Monitoring option in central admin. If it doesn't come then activate the feature manually using Power shell command.

Example:
Enable-SPFeature FeatureFolderName -Url http://server/site/subsite

Note: you can get the Feature name from the following path:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\FEATURES


    
   
























Sunday, November 15, 2015

Dependency feature 'PPSSiteCollectionMaster' for feature 'PPSSiteMaster' is not activated at this scope.

I was trying to create a new sub site under my site collection while working with Sharepoint 2013 and I got the below error message.

Dependency feature 'PPSSiteCollectionMaster' (id: a1cb5b7f-e5e9-421b-915f-bf519b0760ef) for feature
'PPSSiteMaster' (id:0b07a7f4-8bb8-4ec0-a31b-115732b9584d) is not activated at this scope.
[Cannot provision site: http://servername/sites/site1]

Solution:
1. Go Site Actions -> Site Settings ->Site Collection Administration ->Site collection features ->       PerformancePoint Services Site Collection Features  -> Activate

2. Go Site Actions -> Site Settings ->Site Actions ->Manage site features -> PerformancePoint Services Site Features -> Activate

Powershell to list all SharePoint Site Collections in a web application

Get-SPSite  -Limit All

Powershell to list Content Database details for SharePoint Site Collection

Get-SPContentDatabase -Site 'http://sharepointwebapplicationurl'

Id                           : Content DB ID
Name                     : WSS_Content_DBName
WebApplication    : SPWebApplication Name= XXX
Server                    : XXX
CurrentSiteCount  : 2

Powershell to list all SharePoint Site Collections and subsites a web application


Get-SPSite 'http://sharepointwebapplicationurl' | Get-SPWeb -Limit All

Backup and Restore SharePoint Site using Shell Command


Backup SharePoint Site Shell Command:
Backup-SPSite http://sitename -Path E:\Backup\site_name.bak

Description:
The Backup-SPSite cmdlet performs a backup of the site
collection when the Identity parameter is used. By default, the site collection
will be set to read-only for the duration of the backup to reduce the potential
for user activity during the backup operation to corrupt the backup.

Restore a SharePoint site Shell Command:
Restore-SPSite http://sitename -Path "E:\Backup\file.bak" -Force

Restore a SharePoint site to a specific database Shell Command:
Restore-SPSite http://sitename -Path "E:\Backup\file.bak" -Force -DatabaseName "Database"

Description:
The Restore-SPSite cmdlet performs a restoration of the
site collection to a location specified by the Identity parameter. A content
database may only contain one copy of a site collection. If a site collection
is backed up and restored to a different URL location within the same Web
application, an additional content database must be available to hold the
restored copy of the site collection.

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...