Sunday, August 31, 2014

Error Type: Error occurred in deployment step 'Add Solution': A feature with ID has already been installed in this farm. Use the force attribute to explicitly re-install the feature.

When i was working with migration projects, We have several SharePoint 2010 solutions which we want to deploy to SharePoint 2013 with Visual Studio 2012 running on Windows Server 2012. I get the error "A feature with ID 15/... has already been installed in this farm. Use the force attribute to explicitly re-install the feature."

Solution for this, we need to deploy the solution forcefully and this can be done two ways.

1. From visual studio we can deploy the solution forcefully
2. Using power shell command also we can deploy the solution forcefully.


1. Using Visual Studio

Go to your Features in your project.

i. Open the feature.template.xml file

ii. add AlwaysForceInstall="TRUE" to the below tag

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" AlwaysForceInstall="TRUE">

Now try to deploy the code.

(OR)

i. Click on your project
ii. Go to Features and double click on features
iii. now press F4 to view properties
iv. now change "Always Force install" from false to true.
v. now build and deploy the solution.


2. Using Power Shell

In PowerShell, you can use the -Force parameter of the Install-SPSolution commandlet in order to force the installation of a solution:

Install-SPSolution -Identity <solution_file> -GACDeployment -Force

How to change the user display name in SharePoint

I have one user whose name enter wrongly in Active Directory and that user display name showing as wrongly. The user  information has been changed in the Active Directory and AD synchronising appears to be running every night.

But still user display name showing incorrectly.

I have worked on this couple of days and i got two solutions for this.

Solution 1 - Using Database

http://msdn.microsoft.com/en-us/library/dd588089%28office.11%29.aspx

Generally users info of a web application saved in UserInfo table of respective content database.


Here the query to get user details using login name



Here ukreddy is the domain and uday is the user login name

Now we are going to update user display name i.e. tp_Title is the display name in SharePoint

now user display name changed




Solution 2 using SharePoint object model:

Here the method to update user information

        public static void UpdateUserInfo(int userId, string basepath, string displayName)
        {
            SPWebApplication webApp = SPWebApplication.Lookup(new Uri(basepath));
            SPSiteCollection siteCollections = webApp.Sites;
            foreach (SPSite siteCollection in siteCollections)
            {
                try
                {
                    using (SPWeb web = siteCollection.RootWeb)
                    {
                        var user = web.SiteUsers.Cast<SPUser>().FirstOrDefault(u => u.ID == userId);
                        if (user != null)
                        {
                            if (displayName.Length > 0)
                            {
                                user.Name = displayName;
                                user.Update();
                            }
                        }
                    }
                }
                finally
                {
                    if (siteCollection != null)
                    {
                        siteCollection.Dispose();
                    }
                }
            }
        }

After changing through code here the screen shot for updated user display name