Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Confused event receivers

Posted on 2014-01-27
4
Medium Priority
?
427 Views
Last Modified: 2014-02-02
I've written and deployed a feature. This feature has 3 event receivers.
Each event receiver is tied to its own list using <Receivers ListUrl="Lists/Registrations"> in its respective Elements.xml file.

When I go through and test the receivers they all work as expected except they will often given the returned message (properties.ErrorMessage) of one of the other event receivers!
Could this be a caching issue?
Also, when I attempt to delete a shared document I get the message that only site admins can delete the document (which is how one of the event receivers works on a different list)... none of the 3 event receivers have anything to do with the shared documents library!

The 3 event receivers are tied to the follwing 3 custom lists
<Receivers ListUrl="Lists/Registrations">
<Receivers ListUrl="Lists/PastRegistrations">
<Receivers ListUrl="Lists/Courses">

They are all bound to the ItemDeleting event.
Any ideas?
0
Comment
Question by:QPR
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 39814235
Hi,
which SharePoint version and edition?
How does your environment look alike (no of WFE, App ...)
Could you use Powershell or SharePoint Manager (from codeplex) to get the list associated event receivers?
Could you post your complete feature def XML as well as infos about your coded event receiver (the same for all three or dedicated for each list ...)
Thanks and HTH
Rainer
0
 
LVL 29

Author Comment

by:QPR
ID: 39815845
Sharepoint Server 2010
1 WFE, 1 app server, 1 DB server

I have sharepoint manager 2010 and can navigate through the sites/lists etc but am not sure what info to provide. When I go to the lists I don't see the names of the event receivers. Can you let me know what to provide?

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Scope="Site" Hidden="TRUE" Title="TrainingCourseUtilities" Id="520c6b04-bc00-47e6-871a-d9f10aa0d640">
  <ElementManifests>
    <ElementManifest Location="StopCourseDeletes\Elements.xml" />
    <ElementManifest Location="StopRegDeletes\Elements.xml" />
    <ElementManifest Location="StopPastRegDeletes\Elements.xml" />
  </ElementManifests>
</Feature>

This is the same for all three except for the ListUrl (which I have confirmed are all correct)

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Receivers ListUrl="Lists/Courses">
      <Receiver>
        <Name>StopCourseDeletesItemDeleting</Name>
        <Type>ItemDeleting</Type>
        <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
        <Class>TrainingUtils.StopCourseDeletes.StopCourseDeletes</Class>
        <SequenceNumber>10000</SequenceNumber>
      </Receiver>
  </Receivers>
</Elements>


This code is the samefor all 3 too - just the errorMessage is different

public override void ItemDeleting(SPItemEventProperties properties)
        {
            base.ItemDeleting(properties);

            using (SPSite site = new SPSite(properties.WebUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    int _currentUser = properties.CurrentUserId;
                    SPUser spCurrentUser = web.SiteUsers.GetByID(_currentUser);
                    if(spCurrentUser.IsSiteAdmin == true)
                    {
                        properties.Cancel = false;
                        properties.Status = SPEventReceiverStatus.Continue;
                    }
                    else
                    {
                        properties.Cancel = true;
                        properties.ErrorMessage = "Courses can only be deleted by a site administration";
                    }

                }
            }

Open in new window

0
 
LVL 29

Accepted Solution

by:
QPR earned 0 total points
ID: 39816687
Hold the front page, I am reading where others have had the same issue.
It seems that if the feature is scoped to the site level then the event receivers will be fired on all lists regardless. But if it is scoped to the web lvel then the Receivers ListUrl will be respected. I will change this, redploy and test and let you know.

Why couldn't this be mentioned in Technet/other???
0
 
LVL 29

Author Closing Comment

by:QPR
ID: 39827478
Yep, change the scope to web and it works like a charm
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question