Sunday, 27 July 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, 13 July 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.