Wednesday, March 15, 2017

Clear SharePoint Designer 2013 Cache

 SharePoint Designer 2013 gets confused and acts like an idiot. One way to get it back on track is to reset it’s cache. Here is how,
  1. Close SPD2013
  2. Delete everything at %USERPROFILE%\AppData\Local\Microsoft\WebsiteCache
  3. Delete everything at %APPDATA%\Microsoft\Web Server Extensions\Cache
  4. Go to SPD2013 options –> General –> Application Options –> Uncheck the “Cache site data across SharePoint Designer sessions”
Relaunch SDP. Easy!

Monday, March 13, 2017

Sign in as Different User in SharePoint 2013

One of features used in testing of permissions in SharePoint is "Sign in as Different User" which allows you to log in as another user.  With SharePoint 2013 this option is missing.

To get this feature back follow the below steps :

    Locate and then open the following file in a text editor:  C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\CONTROLTEMPLATES\Welcome.ascx

    Add the following element before the existing "ID_RequestAccess" element:

    <SharePoint:MenuItemTemplate runat="server" ID="ID_LoginAsDifferentUser" Text="<%$Resources:wss,personalactions_loginasdifferentuser%>" Description="<%$Resources:wss,personalactions_loginasdifferentuserdescription%>" MenuGroupId="100" Sequence="100" UseShortId="true" />

    Save the file.

Microsoft has published a KB article on the same : http://support.microsoft.com/kb/2752600.

Get User Profile Information in SharePoint 2013




To retrieve user profile information in SharePoint 2013, we need to add below references in out SharePoint Project.

           1.       Microsoft.Office.Server
           2.       Microsoft.Office.Server.UserProfiles

Refer below code snippets for reference

Code behind :
private void GetUserProfileInfo()
        {
            try
            {
                UserProfileManager usrProfileMgr = newUserProfileManager(SPServiceContext.GetContext(SPContext.Current.Site));
                UserProfile usrProfile = usrProfileMgr.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
                if (usrProfile != null)
                {
                    lblName.Text = usrProfile.DisplayName;
                    string origUrl = (string)usrProfile[PropertyConstants.PictureUrl].Value;
                    if (!string.IsNullOrEmpty(origUrl))
                    {
                        imgUser.ImageUrl = origUrl;
                    }
                    else
                    {
                        imgUser.ImageUrl ="/_layouts/15/images/PersonPlaceholder.96x96x32.png";
                    }
                    lblDesignation.Text =Convert.ToString(usrProfile[PropertyConstants.JobTitle].Value);
                    lblDepartment.Text =Convert.ToString(usrProfile[PropertyConstants.Department].Value);
                    lblEmail.Text =Convert.ToString(usrProfile[PropertyConstants.WorkEmail].Value);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
Here, GetUserProfileInfo() method we have called in Page_Load
protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                GetUserProfileInfo();
            }
        }

Reset Search Index in SharePoint 2013 using Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
 
#Get Search service application
$ssa = Get-SPEnterpriseSearchServiceApplication
 
#Content Source Name
$ContentSourceName "SPSite"
 
#Get the content source
$ContentSource = Get-SPEnterpriseSearchCrawlContentSource -Identity $ContentSourceName -SearchApplication $SSA
 
#Get Each Start Address
$StartAddresses $ContentSource.StartAddresses | ForEach-Object { $_.OriginalString }
 
#Clear Indexed content starts with custom contnet source
$ContentSource.StartAddresses.Clear()
 
#Re-add the start address to content source
ForEach ($Address in $StartAddresses ){ $ContentSource.StartAddresses.Add($Address) }

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered


Problem:
Recently I started facing this issue.
Whenever, I load the PowerShell ISE and Type the command to load the SharePoint PowerShell module, it starts throwing error

“The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.”
The same error comes up in the SharePoint Management Shell.

Solution:
You have someone who has the rights to run powershell add your user as SP Shell Admin.
Add-SPShellAdmin -username DOMAIN\YourUser

That's quite the nobrainer, but what happens if your user is already SPShellAdmin, shown with Get-SPShellAdmin and you get the same error popping up? In that case, something probably happened with the SQL. They restored the farm on another server and did not migrate all the access rights. Just run Add-SPShellAdmin -username DOMAIN\YourUser again and it will set the appropriate permissions.