C# and/or SharePoint Event handler question

Posted on 2009-04-19
Last Modified: 2012-05-06

I am not a C# speaker and I am wondering if, with my supplied code, I can make the commented-out code happen in the function WarrensTest, i.e., can I get the ItemUpdated(SPItemEventProperties properties) properies in that function.


Because I am still yet to get a RunWithElevatedPrivileges example to work. I was using the delegate() option with no luck. If I can use CodeToRunElevated, I may have a chance, but you can't send parameters to functions named with that use...

Thanks in advance.
public class SetPermissions : SPItemEventReceiver


        public override void ItemUpdated(SPItemEventProperties properties)


            //SPFile myFile = properties.ListItem.File;

            //myFile.Properties["debugmsg"] = myFile.Properties["MailTo"].ToString();


            SPSecurity.CodeToRunElevated elevatedWarrensTest = new SPSecurity.CodeToRunElevated(WarrensTest);



        private void WarrensTest()



            SPFile myFile = ???????????????? .ListItem.File;

            myFile.Properties["debugmsg"] = myFile.Properties["MailTo"].ToString();




Open in new window

Question by:warrenrapson
    LVL 4

    Assisted Solution

    Using RunWithElevatedPrivilege requires creating sharePoint Objects in the new elevated privilege context, if you do not do this, your users will gain full privilege, which is not what you are looking for. Look at this for details of implementation :

    Sorry but I do not understand the rest of your questions, I hope this will help.

    Accepted Solution

    What I needed to do was declare a variable:
    private SPItemEventProperties _eventReceived;

    assign it the properties:
    public override void ItemUpdated(SPItemEventProperties properties)
    _eventReceived = properties;

    Then use SPSecurity.CodeToRunElevated where in my supplied code:
    SPFile myFile = ???????????????? .ListItem.File;
    should then read
    SPFile myFile = _eventReceived.ListItem.File;

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    730 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now