Friday, June 24, 2016

Check if SharePoint page is in edit mode in Javascript

If embedded javascript code needs to check if the sharepoint page is in edit mode, the script below can be used.

var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

if (inDesignMode == "1")
{
    // page is in edit mode
}
else
{
    // page is in browse mode
}

Copied from http://sharepoint.stackexchange.com/questions/12792/how-do-i-know-if-the-page-is-in-edit-mode-from-javascript

Wednesday, June 22, 2016

SQL Server error Cannot execute as the database principal because the principal “dbo” does not exist

After restoring adventure works database, when trying to see database diagrams I got an error Cannot execute as the database principal because the principal “dbo” does not exist.

The solution is to reassign database owner using script
use [databasename] EXEC sp_changedbowner 'sa'

More Info

Tuesday, June 21, 2016

Add sharepoint snap in to all powershell windows

The post below explains a very convenient way to add SharePoint snap in to powershell windows on dev server.

In brief:

  1. Run following command in Powershell ISE
    • if (!(test-path $profile.AllUsersAllHosts)) {new-item -type file -path $profile.AllUsersAllHosts –force} powershell_ise $profile.AllUsersAllHosts
  2. Append following code to the newly open powershell file
    • $ver = $host | select version if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" }
Also, you might like the environment path to include some of the key locations e.g.

$env:Path = $env:Path + "C:\Program Files
\Common Files\Microsoft Shared\Web Server Extensions\15\Bin;C:\Windows\System32\inetsrv\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64"


https://blogs.msdn.microsoft.com/kaevans/2011/11/14/add-microsoft-sharepoint-powershell-snap-in-to-all-powershell-windows/

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...