Friday, June 26, 2015

SharePoint User Display issue: Display name incorrect in one site collection

Recently I got an issue in my SharePoint 2013 production environment. One of the user display name not showing properly. Instead of his name, it is showing one of the employee who left the organization. By checking the user details in AD we got the details. AD team updated two emails for one user. One is his own email and other email is one of the employee who left the company. We tracked the issue and updated the profile AD and ran User Profile Sync. Everything worked well till now.

But user still having the issue in one site, his display name not showing correctly. Instead of his name, it is showing employee who left the organization. We are seeing this issue only for one site collection. Tried different approaches like deleting user permissions in the site through UI and using PowerShell commands. Nothing worked.

After Googling the issue, we got the resolution. We are seeing that issue due caching in SharePoint site collection. When I remove and add the data in SharePoint site group, SharePoint site collection user details from all users located in <Site URL>/_layouts/people.aspx?MembershipGroupId=0

To fix the issue, we need to remove the user from all users list and read it to the list. But before that we need to check all the user permissions in the site (including all the groups and individual permissions) and need to re add all the places. 

Hope this helps.

Wednesday, June 24, 2015

Copy-SPSite: Rename/Recreate SharePoint site collection

Most of my clients had a requirement to rename SharePoint site collection in all SharePoint versions including SharePoint 200, 2010 and 2013. To do that we have to take the existing site collection backup, Delete the site collection and Restore it new site collection. If anything happens in this process, we are gone. Nothing left.

But in SharePoint 2013 we got new command, Copy-SPSite command allows us to copy the site collection. This option allows us to duplicate the site collection to new site collection. We have options to specify the destination DB.

Here is the syntax for Copy-SPSite command,

Copy-SPSite Source Site URL [-DestinationDatabase Destination DB] -TargetUrl Target Site URL

We can use this command to copy the site collection in same content DB. Copy-SPSite command will not work for copy the site collection in other content databases. To do this we have to follow backup and restore process.

We can copy host named site collections using Copy-SPSite command.

Copy-SPSite -Identity Source Host Named Site collection URL -TargetUrl Destination Host Named Site collection URL -HostHeaderWebApplication Host Header web application URL

Before that we need to run Remove-SPSiteUrl command as below.

Remove-SPSiteURL -URL Host named Site collection URL

Saturday, June 20, 2015

SharePoint 2013 error – Site stuck up in Read-only mode after interrupted backup

While working with SharePoint 2013 restore and backup I got interesting error in one of my host named site collection (I hope this is generic issue, not specific to host named site collection) saying as shown the image below.

When I try to fix this issue from SharePoint central administration quotas, all the options are disabled and unable to change anything as shown the image below.

By going through some of the blogs, I got the issue. In SharePoint 2013, we are having Manintanence Mode property for SPSite makes SharePoint site is undergoing a Maintenance & is read only. We can set this SharePoint site when content DB is in read only state, or when SharePoint site upgrade, moving SharePoint site in process.
We can fix this error by clearing ClearMaintenanceMode method in SpSiteAdministration object. We can do this by running following command,
$Site = new-object Microsoft.SharePoint.Administration.SPSiteAdministration(SITE URL)  $Site.ClearMaintenanceMode()
This fixed my issue. Hope this helps.

Friday, May 8, 2015

Prevent users to create the my sites in SharePoint

In one of my SharePoint environment, we had issue with my sites. When users click on about us, it automatically creates my site for all the user. All these my sites are created as a site collections in the web application.

We have 2000 people accessing the site and every user creating new my site. So it will be 2000 site collection in one web application. SharePoint can handle that, but we not using any my site features in our environment.
For this we just need to prevent the users to create my sites. We can do that from central admin site User profile service settings as shown below.

Open SharePoint central admin site User profile Service application. Select manage user Permissions.

We can see a popup as shown below. Select Authenticated users and uncheck “Create personal sites” option as shown the image below.
Click on Ok to save the settings.

Hope this will helps.

Monday, April 27, 2015

SharePoint – Back to basics – SPLongOperation for lengthy operations

We have many hidden features in SharePoint in look and feel in Out of Box as well as custom. SPLongOperation One of the hidden feature in custom coding side. This feature exists from SharePoint but many of the users may not be aware of this. SPLongOpearation allows us to inform end users on processing screen while operating lengthy operations like moving documents from one site other, deleting sites etc... And at the end we can have options to close/ redirect the page.

Here is the sample code on usage of SPLongOperation,

                              using (SPLongOperation longOpearation = new SPLongOperation(this.Page))
                                             longOpearation.LeadingHTML = "Title of the long operation";//title message
                                             longOpearation.TrailingHTML = "this will take few sec”//sub message
                                             //Code start
                                             //Write the code that to be processed in long operation
                                             //code ends
                                               HttpContext context = HttpContext.Current;
                                             if (context.Request.QueryString["IsDlg"] != null)
                                                            context.Response.Write("<script type='text/javascript'>window.frameElement.commitPopup();</script>");
                                                             string url = SPContext.Current.Web.Url;
 longOpearation.End(url, SPRedirectFlags.CheckUrl, context, string.Empty);

               catch (Exception ex)
                              SPUtility.TransferToErrorPage(ex.ToString());//transfores us to the error page with error message

In the Begin and End methods for long operation we can have different overloaded methods. By using SPLongOperation.Begin method (String, String, SPLongOperation.BeginOperation) method we can pass title and sub message. Here in the script end method, iam passing redirection URL and checking flags and current context. For more details, here is the full description in msdn.