Thursday, March 27, 2014

SharePoint Device channel

You can check the SharePoint website into different  browser :

Http://domain.com/?DeviceChannel=WindowsPhone
*Where WindowsPhone is the alias name given , While creating a new Device channel.

Know user agent:
http://whatsmyuseragent.com/

SharePoint ECMA Scripts


Create List
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var itemCreateInfo = new SP.ListItemCreationInformation();
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('My Custom Generic List');
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
this.oList = web.get_lists().add(listCreationInfo);

clientContext.load(oList, 'Title', 'Id');

clientContext.executeQueryAsync(Function.createDelegate(this, this.onListCreateSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListCreateSuccess(sender, args) {
    alert("List title : " + this.oList.get_title() + "; List ID : "+ this.oList.get_id());
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


Delete List

<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
list.deleteObject();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onListDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
}
function onListDeleteSuccess(sender, args) {
    alert("list deleted");
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


Delete site :

<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.website = web.get_webs().getByTitle('Rare Solutions');
website.deleteObject();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
}
function onSiteDeleteSuccess(sender, args) {
    alert("site deleted");
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​



Load List Item:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle("Pages");
var camlQuery = new SP.CamlQuery();
var q = '<View><RowLimit>5</RowLimit></View>';
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(DisplayName,Id)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemsLoadSuccess(sender, args) {
    var listEnumerator = this.listItems.getEnumerator();
    //iterate though all of the items
    while (listEnumerator.moveNext()) {
        var item = listEnumerator.get_current();               
        var title = item.get_displayName();
        var id = item.get_id();
            alert("List title : " + title + "; List ID : "+ id);
        }
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


Update List Item:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
list.set_description('My custom generic list description');
list.update();
clientContext.load(list, 'Description');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onSiteLoadSuccess(sender, args) {
    alert("list description : " + this.list.get_description());
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


Create Site:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var webCreateInfo = new SP.WebCreationInformation();
    webCreateInfo.set_description("All about Rare solutions.");
    webCreateInfo.set_language(1033);
    webCreateInfo.set_title("Rare Solutions - SharePoint and .NET");
    webCreateInfo.set_url("RareSolutionsSharePoint");
    webCreateInfo.set_useSamePermissionsAsParentSite(true);
    webCreateInfo.set_webTemplate("BLOG#0");

    this.oNewWebsite = this.web.get_webs().add(webCreateInfo);

    clientContext.load(this.oNewWebsite, 'ServerRelativeUrl', 'Created');

clientContext.executeQueryAsync(Function.createDelegate(this, this.onCreateWebSuccess),

Function.createDelegate(this, this.onQueryFailed));
}
function onCreateWebSuccess(sender, args) {
    alert("Web site url : " + this.oNewWebsite.get_serverRelativeUrl());
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


 Delete ListItem :
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
this.oListItem = list.getItemById(1);
oListItem.deleteObject();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemDeleteSuccess),

Function.createDelegate(this, this.onQueryFailed));
}
function onListItemDeleteSuccess(sender, args) {
    alert("list item deleted");
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


 Load List Data:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle("Images");
clientContext.load(list, 'Title', 'Id');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListLoadSuccess(sender, args) {
    alert("List title : " + this.list.get_title() + "; List ID : "+ this.list.get_id());
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


 Load Site Data:
<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
clientContext.load(web, 'Title');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSiteLoadSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onSiteLoadSuccess(sender, args) {
    alert("site title : " + web.get_title());
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​


 Update List Item :

<script type="text/javascript">
var clientContext = null;
var web = null;
ExecuteOrDelayUntilScriptLoaded(Initialize, "sp.js");
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
this.list = web.get_lists().getByTitle('My custom generic list');
this.oListItem = list.getItemById(1);
oListItem.set_item('Title', 'Praveen Battula Updated');
oListItem.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onUpdateListItemSuccess), Function.createDelegate(this, this.onQueryFailed));
}
function onUpdateListItemSuccess(sender, args) {
    alert("list item updated");
}
   
function onQueryFailed(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}</script>​

 


Monday, December 30, 2013

Create FBA custom Login page in SharePoint 2013

Changes in the Authentication providers:

_layouts/15/SP.FBA/LoginClaims.aspx






After you configure FBA : post


Create a Application page put the HTML tags as below

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginClaims.aspx.cs" Inherits="FBA.LoginClaims" MasterPageFile="~/_layouts/15/errorv15.master" %>
<%@ Assembly Name="Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
   


<asp:Label ID="Name" runat="server" Text="UserName:"/>

<br/>

<asp:TextBox ID="txtUserName" runat="server" Height="22px"/>

<br />

<asp:Label ID="lblPwd" runat="server" Text="Password:"/>

<br/>

<asp:TextBox ID="txtPwd" runat="server" TextMode="Password" 

                                        Height="22px"/>

<br />


<asp:Button ID="btnLogIn" runat="server" Text="Sign In" 

                          onclick="btnLogIn_Click"/>

                    

<br /><br />

<asp:Label ID="lblMsg" runat="server" Text=""/>


</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Vendor Login site..
</asp:Content>




Server side code:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.IdentityModel;
using Microsoft.SharePoint.IdentityModel.Pages;
namespace FBA
{
    public partial class LoginClaims : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            if ((txtUserName.Text.Length > 0 && txtPwd.Text.Length > 0))
            {
                bool authenticated = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, txtUserName.Text, txtPwd.Text);
                if (!authenticated)
                {
                    lblMsg.Text = "Invalid Username or Password";
                }
                else
                {
                    Response.Redirect(Context.Request.QueryString["ReturnUrl"].ToString());
                }
            }
            else
            {
                lblMsg.Text = "Username or Password can't be empty";
            }
        }

    }

 
}

Friday, October 18, 2013

Sharepoint 2010 user profile configuration step by step

Steps is as below

1) Create a new MySite sitecollection
2) Create a new user profile service in manage services.(If already there than delete this and create again)
3) Check the below things
1) Account should be farm account and local admin account.
2) Go to Application server click Run > Secpol.msc > Local policy > User rights Assignment > Allow log on locally Add the user.
        3) Go to DC > Administrative tools > Active directory users and computers > Select domian > Right click select Delegate control > follow the below images.









4) Go to run type service.msc Check Forefront identity manager services and Forefront identity manager synchronization services should run with 
domain account try to use the same account as above with service Service type Automatic. Do not  start it now. This will be automatic start once you start the machine.
5) Go to SharePoint central admin > Application management > manage services on server > start user profile services > Start user profile synchronization services.
6) Restart the machine. Once done check userprofile service , both forefront service in services .msc and also check the user profile synchronization services in SharePoint CA.



Thursday, October 10, 2013

SP Powershell command for Backup and Restore

site collection backup:
backup-spsite -identity http://gss-w7g-0793 -path \\GSS-W7G-0793\share\rootsite.bak

restore:
restore-spsite -identity http://gss-w7g-0793 -path \\GSS-W7G-0793\share\rootsite.bak



site backup
export-spweb -identity "http://gss-w7g-0793/Training Blank Site" -path \\GSS-W7G-0793\share\TrainingBlank.cmp -IncludeUserSecurity

restore
import-spweb -identity "http://gss-w7g-0793/Training Blank Site" -path \\GSS-W7G-0793\share\TrainingBlank.cmp  -IncludeUserSecurity


document library backup
export-spweb -identity http://gss-w7g-0793 -path \\GSS-W7G-0793\share\DocumentLib.cmp -itemurl /DC

document library restore
Import-SPWeb -Identity http://gss-w7g-0793 –Path \\GSS-W7G-0793\share\DocumentLib.cmp –UpdateVersions -Overwrite


list backup
Export-SPWeb -Identity http://gss-w7g-0793 -Path \\GSS-W7G-0793\share\listBackup.cmp -ItemUrl "/Lists/Calendar"

restore
Import-SPWeb http://site –Path export.cmp –UpdateVersions -Overwrite


document library backup
Export-SPWeb -Identity http://gss-w7g-0793 -Path C:\SP2010_Backups\testlibbkp2s.cmp -ItemUrl test -Force






Tuesday, October 1, 2013

SPServiceApplicationPool

Get-SPServiceApplicationPool 
# This will show all service application pool 
Remove-SPServiceApplicationPool TestServiceWebApplicationPool
# This will remove service application pool 

Thursday, September 26, 2013

AZURE ACS for SharePoint powershell command

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("C:\Certs\AzureACS.cer")
$map1 = New-SPClaimTypeMapping -IncomingClaimType "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "emailaddress" –SameAsIncoming
$realm=”http://india.internal.com/”
$ap=New-SPTrustedIdentityTokenIssuer -Name "Azure ACS_indigo" -Description "For india.internal.com" –Realm $realm -ClaimsMappings $map1 -ImportTrustCertificate $cert -SignInUrl "https://thisisatest-sb.accesscontrol.windows.net/v2/wsfederation?wa=wsignin1.0&wtrealm=http://india.internal.com/" -IdentifierClaim $map1.InputClaimType
New-SPTrustedRootAuthority -Name "ACS_sp2013_indigo" -Certificate $cert


https://thisisatest-sb.accesscontrol.windows.net/v2/wsfederation?wa=wsignin1.0&wtrealm=http://globalapp.internal.com/

$ap=Get-SPTrustedIdentityTokenIssuer

http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress

HTML

Script:

JS