Friday, March 14, 2014

Change SharePoint site time format


In SharePoint calendar by default we can see the view as Day/week in 12 hour format, not in 24 hour format. We can to change the format from 12 hour to 24 hour through UI or using PowerShell commands.

We can change that through UI by following steps,

Navigate to SharePoint Site settings page and in Site Administration section click on “Regional settings” link



In Time format drop down select 24 hour format. Click on ok to save the settings.


We can change the format using following Powershell commands,

$site = Get-SPSite <SiteCollectionURL>
$web = $site.OpenWeb()
$web.RegionalSettings.Time24=$True
$web.RegionalSettings.FirstDayOfWeek=1
$web.Update()
$web.Dispose()
$site.Dispose()


Wednesday, March 12, 2014

Check current logged-in user having permissions to specific group in SharePoint SPServices

We can check the groups for current logged-in user from SPServices code using “GetGroupCollectionFromUser” opration. Before the we have to download and add folowing files. Javascript 1.7.1.js and JQuery.SpServices-0.7.1a.min.js

Following script will used to get the user group details

$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: $().SPServices.SPGetCurrentUser(),
async: false,
completefunc: function (xData, Status) {
var count = 0;
$(xData.responseXML).find("Group").each(function () {
if ($(this).attr("Name") == "Group Name") 
{ 
count++; 
}
 }); 
if (count == 0) {
// do some action
}
else {
// do some action
}
}
});

Tuesday, March 11, 2014

Change default home/welcome page in SharePoint site using PowerShell commands

We can change SharePoint default home page in different ways as using Site settings if publishing feature already enabled, SharePoint object model code, Using SharePoint designer and PowerShell commands.
We can change the home page by running following PowerShell commands,

Get the Site details by using Get-SPSite command and web by using OpenWeb() method.

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)

Get the root folder for the web by using RootFolder property

$rootFolder = $objWeb.RootFolder

Change the home page by assigning Welcomepage property as shown below

$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx”
$rootFolder.update()

After updating the page, we have to dispose the site and web objects because that objects are created newly.

$objWeb.dispose()
$objSite.dispose()

By combing the all the commands we can see the script as

$objSite = Get-SPSite SiteURL
$objWeb = $objSite.OpenWeb(“Sub site”)
$rootFolder = $objWeb.RootFolder
$rootFolder.Welcomepage = “SitePages/SureshHomePage.aspx”
$rootFolder.update()
$objWeb.dispose()
$objSite.dispose() 

Sunday, March 9, 2014

SharePoint content search web part – Show items sorted by Modified date

Working with SharePoint 2013, I got a requirement from client to implement a search query web part. We have to display the items depending on the modified date. Everything in my content search web part is working as expected. But I am unable to see items modified today.

I have started full crawl again but results are not showing as expected. By checking the Content Search Web part settings, in sorting section we can see the field for date modified as “lastModifiedTime” applied the search filter. I got same results as earlier.

After digging into deep, instead of changing out of box settings, created new one in SharePoint search with Name Modified as shown image below.



Creating the search, started SharePoint full crawl and In Content Search Web part settings, changed Modified managed property.


Super, It worked for me. Now I am able to see the items in CSWP in sorting order.

Saturday, March 8, 2014

SharePoint 2013 Exception “Unknown exception occurred while executing a SharePoint solution”

In SharePoint 2013 adding Sandboxed solution I got an error as “Unknown exception occurred while executing a SharePoint solution” as shown blow.


By checking the ULS logs, I have found the following text as “An unknown exception occurred while executing a sandboxed code solution request in the worker process.\r\n|0 – userCodeWrapperType.FullName = “Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper”

I have checked by changing the application pool identity, checked sandboxed service is running is not. But still I am getting the same error. My current running server is a standalone server with Windows Server 2012, Domain Controller, SQL Server 2012, SharePoint 2013, and Visual Studio 2012.


By digging this into deep, found that there is no fix for this issue, we have to create the new environment. By enabling verbose logging for Sandboxed code solution it will give us temporary fix but not permanent.