locked
EventReceiver does not fire for other users than Administrator RRS feed

  • Frage

  • Hi all

    My code adds a EventReceiver to some SPLists. When I log into Sharepoint as Administrator, then the EventReciever is fired.

    When i log in as an other user, it does nothing.

     

    My current code is this:

    string assm = "Minimizer, Version=" + FileVersionInfo.GetVersionInfo(Root.Res.DLL).FileVersion + ", Culture=neutral, PublicKeyToken=d2d19387a15c363f";
              string cls = "MinimizerPlugin.Minimizer";
              l.EventReceivers.Add(SPEventReceiverType.ItemUpdated, assm, cls);
              l.EventReceivers.Add(SPEventReceiverType.ItemAdded, assm, cls);
    

    What can I do to register this EventReceiver to all users?

    Thanks for your help!!

    Montag, 23. August 2010 09:38

Antworten

  • Hey I found the problem xD

    It had nothing to do with Sharepoint. It's too stupid to say it ;)

    But: Big Thanks for all the help!!

    Greetz


    • Als Antwort markiert FlashFanX Mittwoch, 25. August 2010 18:13
    Mittwoch, 25. August 2010 18:13

Alle Antworten

  • Hi there,

    This problem arises when you are trying to read data from or write data into sharepoint list while you are using some form of authentication on your sharepoint environment. What you need to do is to run your code inside 'ElevatedPrivileges' block which essentially means while your end user is raising event handler action but the code will be running in the context of Admin account.

    Please read the following posts to get to know more about this.

    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

    http://msdn.microsoft.com/en-us/library/bb466220(office.12).aspx

    http://sahanganepola.blogspot.com/2009/08/spsecurityrunwithelevatedprivileges.html
    http://www.sharepointboris.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/

    Hope this helps,

    Thanks

    Montag, 23. August 2010 10:28
  • Hi FlashFanX,

    Thanks to share your problem.

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
      using (SPSite Site = new SPSite(siteurl))
      {
        using (SPWeb Web = Site.OpenWeb(webId))
        {
          // put your logic here
        }  
      }
    });

    Hope this will help



    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    Montag, 23. August 2010 11:23
  • Thanks for your answers!

     

    I've tried it out, but it didn't work.

    I think the event doesn't fire, but how can I check if it is ture?

    I tried the following:

     

        public override void ItemAdded(SPItemEventProperties properties) {
          properties.ErrorMessage = "some xxx";
          properties.Status = SPEventReceiverStatus.CancelWithError;
          properties.Cancel = true;
          Minimize();
        }
    

     

    But there is no Errorpage!!

    But Minimize is called, when loggen in as Administrator :S

     

    Has anyone an idea?

     

    Thanks for you help!

    Montag, 23. August 2010 12:51
  • OK maybe you need more details.

    I have a program in wich you can navigate through webs and lists. Here you can check the lists wher you want to add the EventReceiver.

    When clicking on "start", on all checked lists will be added a EventReceiver. I realized this with the code from the first post.

    When clicking on "stop", all EventReceivers will be deleted.

     

    When i run this program as administrator, click start and then upload a file, the event receiver is called.

    When i upload a file as another user, the event receiver is NOT called.

     

    I tried to create a file on the harddisk, i tried to start cmd, i tried so much

    as administrator: no problem

    as another user: nothing happened

     

    What can I do?

    Same problem on Sharepoint Server 2007 & Sharepoint Server 2010... :S

    Is there no way to add an eventhandler GLOBAL and not only for one user?

    I really need help...

    Montag, 23. August 2010 13:58
  • Ok I've created a complete new EventReceiver for testing.

    namespace MinimizerPlugin {
     public class Minimizer :SPItemEventReceiver{
     public override void ItemAdded(SPItemEventProperties properties) {
      SPSecurity.RunWithElevatedPrivileges(delegate( ) {
      SPListItem item = new SPSite(properties.SiteId).OpenWeb().Lists[properties.ListId].GetItemById(properties.ListItem.ID);
      item["Description"] = "it works!!";
      item.Update();
      });
     }
     } 
    }

    Same problem. When I am logged in as Administrator in sharepoint and adding an item, thet it works.
    When I am logged in as another user, the Field "Description" is empty.

    Any ideas?

    Montag, 23. August 2010 15:23
  • Am I really the only one with this problem?
    Dienstag, 24. August 2010 05:50
  • Hi FlashFanX,

    Sorry for delay...I think This may be the problem of your event reciever i.e. ItemAdded.

    Can you please try with ItemAdding insted of ItemAdded.

    Let me know the result.


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"
    Dienstag, 24. August 2010 06:09
  • Thanks so much for your Answer!!

    I`ve tried to cancel an upload using this code:

     

    public override void ItemAdding(SPItemEventProperties properties) {
     properties.Cancel = true;
     properties.ErrorMessage = "Called";
     }
    

     

    Admin: works perfectly

    Other user: can still upload files and create items without error message...

    Same on Sharepoint 2007 and 2010

    It's really confusing... :S

     

    now I've tested it with WSS 3. Here is the same problem, too.

    this is so crazy :S

    Dienstag, 24. August 2010 07:58
  • Can it be, that I have something misconfiguret at the sharepoint?

    Is there a setting to fire EventReceivers only for specific users?

     

    When no... Can someone send me a sample program that definitive works?

    So I can check if is a problem of all my sharepoint servers, or it is my code.

     

    I really thank you for your help!

    Dienstag, 24. August 2010 16:24
  • I've tried now to register the eventhandler manually with xml files:

    Feature.xml

     

    <Feature Scope="Web" 
      Title="MinimizerPlugin" 
      Id="c9e02684-1001-4c6c-8c34-e4fd607a51d8" 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
      <ElementManifest Location="Elements.xml"/>
      </ElementManifests>
    </Feature>
    

     

    Elements.xml

     

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Receivers ListTemplateId="101">
      <Receiver>
      <Name>MinimizerPlugin</Name>
      <Type>ItemAdding</Type>
      <SequenceNumber>22500</SequenceNumber>
      <Assembly>Minimizer, Version=1.0.9.31, Culture=neutral, 
      PublicKeyToken=d2d19387a15c363f</Assembly>
      <Class>MinimizerPlugin.Minimizer</Class>
      <Data></Data>
      <Filter></Filter>
      </Receiver>
    </Receivers>
    </Elements>
    

     

    Then I've installed and activated the Feature with the following commands:

     

    stsadm -o installfeature -filename MinimizerPlugin\feature.xml
    stsadm -o activatefeature -filename MinimizerPlugin\feature.xml -url http://localhost/
    

    I have still the same problem. it works only for the administrator. It's really really confusing...

    But i know now, that it's not a problem of the registration. It must be the EventReceiver DLL or a Configuration of Sharepoint.

    Has someone an idea?

    Mittwoch, 25. August 2010 09:17
  • Hey I found the problem xD

    It had nothing to do with Sharepoint. It's too stupid to say it ;)

    But: Big Thanks for all the help!!

    Greetz


    • Als Antwort markiert FlashFanX Mittwoch, 25. August 2010 18:13
    Mittwoch, 25. August 2010 18:13