Sunday, March 13, 2016

Fab40 for SharePoint 2013


Fab40 for SharePoint 2013

Fab 40 templates were free templates released by Microsoft for sharepoint 2007 and wss 3.0 to address some of the common scenarios encountered by SharePoint administrators, developers and event business/Marketing managers to demonstrate and show case some of the capabilities of MOSS to end users.

Discussion about that how good these templates are and in which scenario these are more helpful versus things which needs to be improved in these templates is a separate topic but I have noticed many SharePoint people using these templates either for small clients , for demonstration purpose and even for training purposes etc. ..

I have uploaded some of these Fab 40 templates for SharePoint 2010 and SharePoint 2013, so now you can have Fab 40 for SharePoint 2010 and SharePoint 2013, at least some of these are available for now…


http://sharepointwebstore.com/product-category/sharepoint-2013/

Wednesday, March 09, 2016

The Problem
Consume web services (running on HTTPS) in SharePoint and SSL certificate is not registered in SharePoint under TRUST Authority.
Related Errors


  • Web Services: Could not establish trust relationship for the SSL/TLS
  • Server was unable to process request. ---> The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
  • An operation failed because the following certificate has validation errors:Subject Name: CN=xxxx.com Issuer Name: CN=XXXTRUST AuthorityName DV SSL CA - G3, OU=Domain Validated SSL, O=GeoTrust Inc., C=US Thumbprint: 3495DB5381AC3EXXXXXX9  Errors:   PartialChain: A certificate chain could not be built to a trusted root authority.  RevocationStatusUnknown: The revocation function was unable to check revocation for the certificate.  OfflineRevocation: The revocation function was unable to check revocation because the revocation server was offline.  . 1b31659d-b408-b0d3-ae61-808af97de845



Note: These errors are applicable to other web applications as well and are not limited to SharePoint.


ResolutionTo overcome this error, you need to add the certificate(of Web Service Running on SSL) to SharePoint Manage Trust Authority. 

Downloading the Certificate:
First Step is to down the certificate of web service.1) Open Web service in Browser. 2) Click the Lock in address bar if you are using chrome, its on right hand side if you are using I.E
3) Click View Certificate 
4) Add a new Certificate





2) Click Details





4) Select Certification Path-> Select the top level Certification Path (STEP 1)->View Certificate (SEP 2)->Details tab->Copy to File(Step 3) -> Next -> Select the format as DER encoded binary X.509 (.CER)




Repeat Step 4 for Top level certificate and levels below it (LEVEL 1 &2 in this case)


By Now you should have certificate files (2 files in this example) on your local machine in .cer format.




Add Certificate to SharePoint

1) Open SharePoint Central Admin
2) Click Security
3) Under General Security select Manage Trust





5) Select the certificate which you have saved in previous step, Repeat this for all downloaded certificates. (2 Certificates in this example)

Sunday, January 17, 2016

SharePoint Wakeup script Configuration in Task Scheduler

This script will access your SharePoint site specified in URL (in script) after every few minutes and will keep the application pool warm thus making it quicker for users to access the site.

1) Log on to SharePoint Server

2) Copy Script below in a  file and save that file as spwakeup.ps1

function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
{
    $error = $false
    $webRequest = [System.Net.HttpWebRequest]::Create($url)
    $webRequest.Timeout = 300000
    if($cred -eq $null)
    {
        $webRequest.Credentials = [system.Net.CredentialCache]::DefaultCredentials
    }
    try {
    $res = $webRequest.getresponse()
    }catch{
    $error = $true
    }
}
   
Function Load-SharePoint-Powershell
{
     If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
     {
              Write-Host -ForegroundColor White " - Loading SharePoint Powershell Snapin"
          Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction Stop
     }
}
Load-SharePoint-Powershell
$webapplications = Get-SPWebApplication [SITEURL]
$AllSites = Get-SPSite -limit all
$Array = @()
$i=0
foreach ($wa in $webapplications)
{
    foreach ($windowsauth in $wa.AlternateUrls)
    {
        $authenticationprovider= Get-SPAuthenticationProvider -webapplication $wa -zone $windowsauth.Zone
        If ($authenticationprovider.UseWindowsIntegratedAuthentication)
        {
            $accessableURL = $windowsauth.IncomingUrl
        }
    }
    if (!$AccessableURL) {$accessableURL = $wa.url -replace ".$"}
    foreach ($site in $AllSites)
    {
        if ($Site.Url -and $Site.Url+"/" -match $wa.url)
        {
            $subsites = Get-SPSite $Site.Url | Get-SPWeb -Limit All
            Foreach ($subsite in $subsites)
            {
                $i++
                Write-Progress -activity "Looking up all sites" -status "Please Wait..." -PercentComplete (($i / 500) * 100)
                $PlainWaUrl = $wa.Url -replace ".$"
                $WakeUpSite = $Subsite.Url.replace($PlainWaUrl, $accessableURL)
                $Array = $Array + $WakeUpSite
                #$html=get-webpage -url "$WakeUpSite" -cred $cred;
                if ($i -eq 500){$i=0}
            }
        }
    }
    Remove-Variable accessableURL
}

$i=0
Foreach ($Website in $Array)
{
    $i++
    Write-Progress -activity "Waking up sites" -status "Waking: $Website" -PercentComplete (($i / $Array.Count) * 100)
    $html=get-webpage -url "$Website" -cred $cred;
}


3) Click Start-> Administrative Tools - > Task Scheduler

2) Expand the left hand tree and right click on Task Schedule Library to create a new Task.


3) Give your task a friend name.

4) In General section come to  Security Options select the following options
a) Run whether user is logged on or not
b) Run with highest privileges
c)  Hidden

5) In Triggers section , add a new trigger and specify the following.

a) Begin the task -> on a schedule
b) Settings:
 One Time
Start date and time should be today's date and time
c) Advanced Settings - > Select Enabled.

6) Select Actions and add a new Action

a) Action -> Start a Program
b) Program/script - > PowerShell.exe
c) add a arguments (optional) -> Execution Policy bypass "Path of script file which you have saved in step 2"


7) Select the Conditions tab and in power section select
a) Start the task only in the computer is on AC Power

8) Select the Settings tab and select

a) Allows task to be run on demand
b) Stop the tasks if it runs longer than 5 days
c) If the running task does not end when requested, force it to stop.
d) Do not start a new instance


9) Click Ok.



Build trust relationship with local domain of SharePoint server and Other Domain so that users of trusted domain can be used in SharePoint

Build trust relationship with local domain of SharePoint server and Other Domain so that users of trusted domain can be used in SharePoint

Scenario: 

  • SharePoint Farm installed in domain1.com 
  • All company users are registered in domaininternal.com 
  • Requirement: Add users from domaininternal.com to SharePoint site collection which is running in domain1.com 


Run this on Sharepoint PowerShell:

stsadm.exe -o setproperty -url -pn "peoplepicker-searchadforests" -pv "", ,,


Important: LoginName is the login name of user who is domain administrator or added to domain admin group, the command will run otherwise but the results will be be as desired.


Good References for this:
https://blog.tallan.com/2013/04/18/setting-up-an-external-domain-trust-in-a-simple-sharepoint-2010-extranet-with-separate-ad-domains-and-completing-a-profile-sync/

http://www.boostsolutions.com/blog/how-to-add-trust-domains-in-a-sharepoint-farm/

http://blog.sharepoint-voodoo.net/?p=17

Lock/Unlock FBA Account

If you have FBA packed installed , it can be used to unlock an account but if you want to unlock many accounts SQL statement below can be used to do that.

Un-Lock FBA Account
Update [DBNAME]
set IsLockedOut=0 ,FailedPasswordAttemptCount=0

where  IsLockedOut=1 and   LastLockoutDate=DateAdd(Minute,30,LastLockoutDate)


P.S: where clause can be modified to add different criteria.  

SharePoint 2013 - Get User Title and Email

var context = new SP.ClientContext.get_current();
web = context.get_web()
 var currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(
var userObject = web.get_currentUser();
console.log(userObject.get_email());
console.log(userObject.get_loginName());
console.log(userObject.get_title());
);

SharePoint 2013 - Set and Get Value for Hyperlink Field in JSOM

Set and Get Value for Hyperlink Field in JSOM


Set Value
var urlvalue = new SP.FieldUrlValue();
urlvalue.set_url('www.google.com');
urlvalue.set_description('Title');
oListItem.set_item("URL", urlvalue);



Get Value
console.log(fvalue.get_url());
console.log(fvalue.get_description());