Monday, March 13, 2017

Compare SPUser objects in SP code


I have to compare the User value in the Assigned To Field of the List with the other User value.
Here is the exact code that will do this.

SPUser spUser = GetSPUserOne();
SPUser spPrevUser = GetSPUserTwo();

For Windows Authentication This will do

if(spUser.Sid.Equals(spPrevUser.Sid))
{
…..
}

For FBA you have to follow this

if(spUser.UserToken.CompareUser(spPrevUser.UserToken))
{
…..
}

Friday, March 10, 2017

How to check the SharePoint Installation Type – Standalone or Farm

The solution is to launch the Registry Editor (regedit.exe) and check for the Server Role at the following location depending on the SharePoint version:

SharePoint 2007: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\WSS\ServerRole
SharePoint 2010: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\WSS\ServerRole
SharePoint 2013: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\WSS\ServerRole

Tuesday, March 7, 2017

Enable custom erro in Web.config file in SharePoint

Every change you make in that config files have no effect on the web application. You have to go the web.config file that is generated once the web application is created.
So edit the web.config file in C:\inetpub\wwwroot\wss\VirtualDirectories\your port number and modify the parameters you have indicated in that web.config file:
·         customErrors mode must be "Off"
·         compilation debug must be "true"
·         SafeMode CallStack must be "true"

The 'your port number' piece of path is the

SPDesigner cache clearing

rmdir "%LOCALAPPDATA%\Microsoft\WebsiteCache\" /s /q
rmdir "%APPDATA%\Microsoft\SharePoint Designer\ProxyAssemblyCache\" /s /q

Tuesday, February 28, 2017

PowerShell snippets for SharePoint branders

1. Change Master Page for all sites in the collection



# ----- For publishing sites and non publishing sites
$site = Get-SPSite http://intranet
foreach ($web in $site.AllWebs) {
$web; $web.CustomMasterUrl = "/_catalogs/masterpage/V4.master";
$web.Update(); $web.CustomMasterUrl;
$web.Dispose()
}
foreach ($web in $site.AllWebs) {
$web; $web.MasterUrl = "/_catalogs/masterpage/v4.master";
$web.Update(); $web.MasterUrl;
$web.Dispose()
}
$site.Dispose()
write-host "Complete! V4.master is now applied";


2. Set alternate CSS

$web = Get-SPWeb http://intranet
$web.AlternateCssUrl = "/Style Library/main.css"
$web.AllProperties["__InheritsAlternateCssUrl"] = $True
$web.Update()
3. Set a site logo



(get-spsite http://intranet).AllWebs | foreach {
$_.SiteLogoUrl = "/Style%20Library/ClientLogo.png";


4. Set regional setting/locale

$site = Get-SPSite http://intranet
foreach ($web in $site.AllWebs) {
$web; $web.Locale = 1053;
$web.Update(); $web.Locale;
$web.Dispose()
}
$site.Dispose()


5. Set a theme

$SiteUrl = "http://peakfinders/"
$NewTheme = "Azure"
# Loading Microsoft.SharePoint.PowerShell
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null) {
Write-Host "Loading SharePoint Powershell Snapin"
Add-PSSnapin "Microsoft.SharePoint.Powershell"
}
# Setting site themes on sites and sub sites
$SPSite = Get-SPSite | Where-Object {$_.Url -eq $SiteUrl}
if($SPSite -ne $null)
{
$themes = [Microsoft.SharePoint.Utilities.ThmxTheme]::GetManagedThemes($SiteUrl);
foreach ($theme in $themes)
{
if ($theme.Name -eq $NewTheme)
{
break;
}
}
foreach ($SPWeb in $SPSite.AllWebs)
{
$theme.ApplyTo($SPWeb, $true);
Write-Host "Set" $NewTheme "at :" $SPWeb.Title "(" $SPWeb.Url ")"
}
}
Write-Host "Themes updated at:" $SPSite.Url -foregroundcolor Green