C# and/or SharePoint Event handler question


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

Who is Participating?
warrenrapsonAuthor Commented:
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;
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 : http://msdn.microsoft.com/fr-fr/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

Sorry but I do not understand the rest of your questions, I hope this will help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.