QPR
asked on
Confused event receivers
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/Registratio ns"> 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/Registratio ns">
<Receivers ListUrl="Lists/PastRegistr ations">
<Receivers ListUrl="Lists/Courses">
They are all bound to the ItemDeleting event.
Any ideas?
Each event receiver is tied to its own list using <Receivers ListUrl="Lists/Registratio
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/Registratio
<Receivers ListUrl="Lists/PastRegistr
<Receivers ListUrl="Lists/Courses">
They are all bound to the ItemDeleting event.
Any ideas?
ASKER
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="TrainingCourseUtili ties" Id="520c6b04-bc00-47e6-871 a-d9f10aa0 d640">
<ElementManifests>
<ElementManifest Location="StopCourseDelete s\Elements .xml" />
<ElementManifest Location="StopRegDeletes\E lements.xm l" />
<ElementManifest Location="StopPastRegDelet es\Element s.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>StopCourseDeletesIte mDeleting< /Name>
<Type>ItemDeleting</Type>
<Assembly>$SharePoint.Proj ect.Assemb lyFullName $</Assembl y>
<Class>TrainingUtils.StopC ourseDelet es.StopCou rseDeletes </Class>
<SequenceNumber>10000</Seq uenceNumbe r>
</Receiver>
</Receivers>
</Elements>
This code is the samefor all 3 too - just the errorMessage is different
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="TrainingCourseUtili
<ElementManifests>
<ElementManifest Location="StopCourseDelete
<ElementManifest Location="StopRegDeletes\E
<ElementManifest Location="StopPastRegDelet
</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>StopCourseDeletesIte
<Type>ItemDeleting</Type>
<Assembly>$SharePoint.Proj
<Class>TrainingUtils.StopC
<SequenceNumber>10000</Seq
</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";
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep, change the scope to web and it works like a charm
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