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

Sunday, July 27, 2014

How to disable event firing on list item events in SharePoint 2013

If you want to update the current item metadata or other item metadata in a list or library and also does NOT need to fire another event for the other item you've updated.

Solution 1:

  SPList list = web.Lists.TryGetList("Custom");
  SPListItem item = list.GetItemById(34);
  item["Title"] ="Updated Successfully";
  EventFiring eventFiring = newEventFiring();
  eventFiring.DisableHandleEventFiring();
  item.Update();
  eventFiring.EnableHandleEventFiring();

What I dislike about the solution, is the risk of leaving the events disabled. Assume an exception occurs, the code will never reach the line where the event firing is enabled (restored) again.

I would like to show you the best way to do it. I suggest a using-pattern, much like the TransactionScope class used for db transactions in the entity framework.

///
/// Disabled item events scope
///
class DisabledItemEventsScope : SPItemEventReceiver, IDisposable
{
   bool oldValue;
   public DisabledItemEventsScope()
   {
      this.oldValue = base.EventFiringEnabled;
      base.EventFiringEnabled = false;
   }
   public void Dispose()
   {
      base.EventFiringEnabled = oldValue;
   }
}
and in your event receiver method ItemAdded, ItemUpdated, or others.

public override void ItemUpdated(SPItemEventProperties properties)
{
   base.ItemUpdated(properties);
   SPListItem currItem = properties.ListItem;
   using (DisabledItemEventsScope scope = new DisabledItemEventsScope())
   {
      currItem["Column2"] = "updated Sucessfully";
      currItem.Update();
   }
}

Error: This item is no longer available it may have been deleted by another user click ok to refresh the page

Problem: I have upgraded my SharePoint environment from 2010 to 2013. When clicking on the ECB menu of Post list in SharePoint 2013, was getting the following error message.

"This item is no longer available it may have been deleted by another user click ok to refresh the page".

I have tried different ways to resolve but was not able to do.

Then i thought the OOB ListViewWebPart in ViewAllDocument.aspx is corrupted for the post list,
so in order to resolve the issue please replace this with new ListViewWebPart.

Here the steps for solution for this.

1. I open the site in SharePoint designer
2. Then Go to lists in view all
3. Then click on Post list
4. Then navigate to page and select "All Document.aspx"
5. Now open the page in "Edit File in Advanced Mode".
6. Now hide the default listform webpart by change <IsVisible>true</IsVisible> to <IsVisible>false</IsVisible>.

7. Click on inbetween zonetemplate and Click on insert tab from the ribbon.

Now click on DataView from that insert new ListViewWebpart for the post list and Save.

Solved...



Issue: Blog category view not filtering properly in SharePoint 2013 after migration from SharePoint 2010

I have Post list in SharePoint 2010 and whenever user posting a post he has to select a category.
And after posting a post user can see his post and below that post it shows category name also when user clicks on that category it redirects to categories page and shows list of post which are posted under that category.

Everything is working fine in SharePoint 2010, Now i have upgraded my SharePoint environment from 2010 to 2013.

Now the issue is, whenever user clicks on category under any post it is redirecting to categories page but it is showing all posts irrespective of what user selected category.

Here is the solution,

1. Click a category name on the left, or navigate to /BlogName/Lists/Categories/Category.aspx
2. Go into Edit Page mode, and add a Query String (URL) Filter web part.
3. In the web part properties, Filter name = Name, Query String Parameter name = Name (don't change this to anything else, it has to say "Name") Check the box "send empty if there are no values"
4. OK, and remove the filter from the view on the Posts web part.
5. Create a web part connection that connects the Query String URL Filter to the Posts web part, using the "Category" field.


Sunday, July 13, 2014

Error Type: SPSecurityContext: Request for security token failed with exception: System.ServiceModel.ServiceActivationException: The requested service, 'http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc' could not be activated.

Hi Today when i try to deploy my small app on SharePoint 2013 environment, i got the following error,

Cannot connect to the SharePoint site: http://ukreddy:3430/. Make sure that this is avalid URL and the SharePoint site is running on the local compurter. If you move this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL property of the project.



I know that the site is running and up. Am sure something stopping the deployment. So, i checked the log files and i found the bellow exception
"SPSecurityContext: Request for security token failed with exception: System.ServiceModel.ServiceActivationException: The requested service, 'http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc' could not be activated."



and when i browse to the URL "http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc
" Then i got the following error in my browser


"Memory gates checking failed because the free memory is less than 5% of total memory. As a result, the service will not be available for incoming requests. To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element."



Then i came to know that there is an issue with the memory, then i checked task manager and observed that Memory reached more than 95%.



then i killed some tasks and again i browse the URL

Now i can see the page without error.



Then i deployed the solution successfully.

Sunday, June 1, 2014

How to show site column in SharePoint 2013 search refinement panel

Scenario:

I have create one site column of choice type and i use this column in document library/lists.

I have uploaded documents and while uploading i have selected values for that site column.

Now i want to show this site column values in refinement for better search results.

HOW TO DO IT?

Solution:

Here the solution....

1. Create Crawled Property
2. Create Mapped Property and Map to the crawled property/Create a Managed Property from a Crawled Property
3. Modifying refinement panel web part

1. Create Crawled Property:

Crawled properties are metadata information that are extracted from the documents and lists during crawls.

In SharePoint, we no need to create crawled property. when we do full/incremental crawl of content source it will automatically create .

Nothing to do in this step, just run full/incremental crawl on content source.

2. Create Mapped Property and Map to the crawled property/Create a Managed Property from a Crawled Property

Go to Central Administrator --> Application Management ---> Manage Service Applications(under Service Applications) --> Click on Search Service Application.

Click on Content Sources under Crawling and select content source then start full crawl.

After that check crawled property created or not

Go to Central Administrator --> Application Management ---> Manage Service Applications(under Service Applications) --> Click on Search Service Application --> Click on Search Schema which is under Queries and Results

Now Click on Crawled Properties


Now search for column name and you can find crawl property 


Now go to Managed Properties


Click on New Managed Property


a. Specify unique name without spaces and description if any
b. Type: leave this option as default.
c. Searchable: If this managed property you want to use in search just choose this option.

d. Queryable: if you want to query on this managed property like "PropertyName:PropertyValues" then choose this option. Example FileType:doc.



e. This is very important, if you want to use this property in refinement panel then choose "yes-active" option from the choices.

f. To sort results based on this property then choose "Yes-Active" option from the choices.


g. Give some alias name for the property.


h. Now add crawled property to this managed property. Click on Add a mapping, it will open pop and display list of crawled properties, search for crawled property and select crawled property and click on OK.




i. leave remaining options as default and click OK

Now you have created managed property and mapped to crawled property also.

Now go back to search schema and search for newly created managed property and it should be look like this.

Now run full crawl on content source. Go to content sources --> select content source and start full crawl.


3.Modifying refinement panel web part
After the full crawl has completed, The final step is to update the refinement web part on the Search Results page for a Search Site.  The steps are the following:
a. Perform a simple search and it will go to search results page
NOTE: Create new site with enterprise search center template.

b. Now hit the gear on the top right of the page and select Edit Page.

c. On the left, hit the pull down next to the Refinement web part and click “Edit Web Part”.

d. The Properties for the Refinement web part will be on the right so select the Choose Refiners… button.


e. On the list of Available refiners on the left, choose the your managed property and click Add.   





f. Hit OK and that should take you back to the Search Results page where you can perform additional Edits.  Hit OK to the Refinement web Part properties dialog on the right.
g.  Check In your changes by hitting the Check In button from the Ribbon and finally Publish.



Now perform search and you can see your site column values in refinement panel also.