Friday, 6 February 2015

Single Sign On Configuration for Office 365 (SSO)

 

1.need to add Federated domain to the site.
  (configuration of  Federated Identity Management (FIM))

2. need to add UPN suffixes to the Forest

3. Create STS(security token service)

4.  Enable and configure Active Directory Federation Services (AD FS) 2.0 (https://technet.microsoft.com/en-us/library/adfs2(v=ws.10).aspx) for intranet if we want external authentication process need to enable Active Directory proxy.

5. test the SSO(Single Sign On) from (https://testconnectivity.microsoft.com/?testid=SingleSignOn)

6. Then configure failures from SSO(Single Sign On) test

-->now you can login from portal page (portal.microsoftonline.com) by using AD user credentials.
--> if you want separate custom login page,you have go though from following steps.  

7. create SSL certificate clearance

8. create the custom login page


9. handle the input credentials from page by CSOM using STS and SSL with OAuth.

to enable sso we have to follow above step by step.... 

Wednesday, 22 October 2014

How To Set Fixed Rows in DataList Control in .NET ASP C#

--> In data list control we can set Repeated columns but we can't set Rows directly Because there is no attribute for that operation.
--> so, to set that fixed rows we have to right the logic.
--> To achieve this requirement we have to update columns size based up on the number of entries or count.
Here I want to take  List from generic collection to set the number of entries as follows

List<int> myList = new List<int>();
for (int i = 1; i <38; i++)
{
myList.Add(i);
}


List<int> myList = new List<int>();
for (int i = 1; i <38; i++)
{
myList.Add(i);
}
     
Now, the above myList consist of 38 elements, if you want to give entries dynamically, take the values from text box.   


List<int> myList = new List<int>();
string entries = textBox1.text;
for (int i = 1; i <convert.Toint32(entries); i++)
{
myList.Add(i);
}


List<int> myList = new List<int>();
string entries = textBox1.text;
for (int i = 1; i <convert.Toint32(entries); i++)
{
myList.Add(i);
}

Now, i want to fix the Rows Size 3, for that we have to use the following logic
                                                                                                                               
         for(j=1;j<myList.Count;j++)                      //count of entries
            {
                if (myList.Count == 3*j)            //if it is multiple by three we can fix the multiple
                {                                                         by three valued columns dynamically
                    columns = j;
                    ViewState["datalist_columns"] = columns;
                }
            }
            if (myList.Count >3*columns)        // if the count is not multiple by three then
            {                                                                we can check the near multiple by three
                columns = myList.Count / 3;             and increase one column because count is 
                columns = columns + 1;                       exceed .
                ViewState["datalist_columns"] = columns;
                      }
            myDataList.RepeatColumns =Convert.ToInt32(ViewState["datalist_columns"]);
            myDataList.DataSource = myList;

CODE In Detail :

.ascx :


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="datalist.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

    <asp:DataList ID="myDataList" runat="server"
          
          RepeatDirection ="Vertical"     
            CellPadding="10"
            ForeColor="#333333"
            RepeatLayout="Table"
            ShowFooter="False"
            ShowHeader="False"
         GridLines="Both">
            <AlternatingItemStyle BackColor="White" />
            <ItemStyle BackColor="#EFF3FB" />
            <SelectedItemStyle BackColor="#D1DDF1"
                Font-Bold="True" ForeColor="#333333" />
            <ItemTemplate>
                <asp:Label ID="myLabel" runat="server"
                    Text="<%# Container.DataItem.ToString() %>" />
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

.CS CODE:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace datalist
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        int columns;
        int j;
        protected void Page_Load(object sender, EventArgs e)
        { 
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            List<int> myList = new List<int>();
            string photos =TextBox1.Text;
            for (int i = 0; i < Convert.ToInt32(photos); i++)
            {
                myList.Add(i);
            }
            for (j = 1; j < myList.Count; j++)
            {
                if (myList.Count == 3 * j)
                {
                    columns = j;
                    ViewState["datalist_columns"] = columns;
                }
            }
            if (myList.Count > 3 * columns)
            {
                columns = myList.Count / 3;
                columns = columns + 1;
                ViewState["datalist_columns"] = columns;
            }
            myDataList.RepeatColumns = Convert.ToInt32(ViewState["datalist_columns"]);
            myDataList.DataSource = myList;
            myDataList.DataBind();
        }
    }
}

Screen Shots :










Monday, 20 October 2014

Custom Timer Jobs in SharePoint 2013

In this article I’m going to explain about creation of custom Timer Jobs in SharePoint 2013 with step by step.  Today I am going to create a timer job that will execute every 5 minutes and creates task in task list of the SharePoint site whichever the site we activated the timer job feature.

What is Timer Job?
A Timer Job is a periodically executed task inside SharePoint Server. It provides us a task execution environment. For example, we can execute tasks like: sending emails every hour, data updating every day, creating reports every week, etc.

By default some Timer jobs are in SharePoint Web Application. Those are,
ü Send mails
ü Validate sites
ü Delete unused sites
ü Health analysis
üProduct versioning
üDiagnostics 
     These tasks will have execution periods like,
 ü  Minute
ü  Hour
ü  Day
ü  Week
ü  Month
Step1:-
    ü  Open Visual Studio and create new project like below shown figure.



   Step2:-
   ü  Select language as visual c#.
   ü            Click on “Office/SharePoint”.
   ü            Select “SharePoint2013-Empty Project”.
   ü            Give name as “SPCustomTimerJob”
   ü            Click on “OK” to create project.


Step3:-
   ü  Provide the site URL to the project where you want deploy the solution.
   ü  Click on Validate button to check the connectivity.
   ü  Select the trusted level to deploy solution check the “Deploy as Farm Solution” because it              has highly trusted than Sandbox solution.
   ü  Click on “Finish”.

Step4:-
              ü Right Click on project name select “Add” then “New Folder”.
   ü  Give the folder name as “SPJobs”.

Step5:-
  üRight Click on “SPJobs” folder and add one class file.



Step6:-
   ü Select the class Template and name it as “TimerJobClass.cs”.
    ü  The class file is created.


  

Step7:-
    ü  Inherit the SPJobDefinition class from SPCustomTimerJob.
    ü  Add the three default constructors of SPJobDefinition class to SPCustomTimerJob.
    ü  Over ride the Execute method in SPCustomTimerJob class.
    ü  Our main code we will keep it in Execute method of the SPCustomTimerJob.



Step8:-
    ü  Right click on Features and “AddFeature” and name it as “SPTimerJobFeature”.



Step9:-
    ü  Select the scope of the Timer job as “WebApplication”.


Step10:-
    ü  Then go to the Feature properties and make “False” the “Active On Default”.

Step11:-
    ü  Right click on the “SPTimerJobFeature” and select “Add Event Receiver”.
    ü  Name it as SPTimer.


Step12:-
If you observer here the SPTimerjobFeature1EventReceiver class extends the SPFeatureReceiver class.

By default all the Methods are commented out, un-comment the methods that you want and add the code inside the method
    ü  FeatureActivated
    ü  FeatureDeactivating
    ü  FeatureInstalled
    ü  FeatureUninstalling
    ü  FeatureUpgrading




Step13:-
   ü  In FeatureActivated method i used SPSecurity.RunWithElevatePrivileges.
   ü  And instantiated the WebApplication and site.
   ü  Implemented two methods create and delete the job are CreateJob() and DeleteJob()



Step14:-
  ü Right click on project name and click on “Deploy” to deploy the solution into the site.



Step15:-
   ü  Go to the Central Administration.
   ü  Select the Application Management then click on the “Manage web applications”.

Step16:-
   ü  Select the web application in which the solution is deployed.
   ü  Click on “Manage Feature”.



Step17:-
   ü  You can find the Feature whatever implemented in visual studio.
   ü  Then click on “Activate” button.



Step18:-
   ü  Then the feature activated as shown in below figure.
   ü  Then click on “OK”.



Step19:-
   ü  Now go to the list to check whether the task is created or not in below shown figure.




TimerJobClass.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SPCustomTimerJob.SPJobs
{
    class TimerJobClass:SPJobDefinition
    {
        public TimerJobClass() : base() { }

        public TimerJobClass(string JobName, SPService Service) : base(JobName, Service, null, SPJobLockType.None)
        {
            this.Title = "Timer Job Task complete";
        }

        public TimerJobClass(string JobName, SPWebApplication web):base(JobName,web,null,SPJobLockType.ContentDatabase)
        {
            this.Title = "Timer Job Task complete";
        }

        public override void Execute(Guid targetInstanceId)
        {
            //base.Execute(targetInstanceId);
            SPWebApplication webApp = this.Parent as SPWebApplication;
            SPList taskList = webApp.Sites[0].RootWeb.Lists["TaskList"];
            SPListItem newtask = taskList.Items.Add();
            newtask["Title"] = "NewTask" + DateTime.Now.ToString();
            newtask.Update();
        }
    }
}
SPTimerjobFeature1.EventReceiver.cs
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using SPCustomTimerJob.SPJobs;

namespace SPCustomTimerJob.Features.SPTimerJobFeature
{
    [Guid("65cf2a1a-6a7e-4426-b63d-9f0be40f85f7")]
    public class SPTimerJobFeatureEventReceiver : SPFeatureReceiver
    {
        const string JobName = "SPTimer Job Task";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPWebApplication parentwebApp = (SPWebApplication)properties.Feature.Parent;
                    SPSite site = properties.Feature.Parent as SPSite;
                    DeleteExistingJob(JobName, parentwebApp);
                    CreateJob(parentwebApp);
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            try
            {
                SPWebApplication parentwebApp = (SPWebApplication)properties.Feature.Parent;
                DeleteExistingJob(JobName, parentwebApp);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;
            try
            {
                TimerJobClass job = new TimerJobClass(JobName, site);

                SPMinuteSchedule schedule = new SPMinuteSchedule();

                schedule.BeginSecond = 0;
                schedule.EndSecond = 59;
                schedule.Interval = 5;
                job.Schedule = schedule;

                job.Update();
            }
            catch (Exception)
            {
                return jobCreated;
            }
            return jobCreated;
        }
        public bool DeleteExistingJob(string jobName, SPWebApplication site)
        {
            bool jobDeleted = false;
            try
            {
                foreach (SPJobDefinition job in site.JobDefinitions)
                {
                    if (job.Name == jobName)
                    {
                        job.Delete();
                        jobDeleted = true;
                    }
                }
            }
            catch (Exception)
            {
                return jobDeleted;
            }
            return jobDeleted;
        }
    }
}


Thank You...!