C# and/or SharePoint Event handler question

Hi,

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.

Why?

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();
            //myFile.Update();
 
 
            SPSecurity.CodeToRunElevated elevatedWarrensTest = new SPSecurity.CodeToRunElevated(WarrensTest);
            SPSecurity.RunWithElevatedPrivileges(elevatedWarrensTest);
        }
 
 
        private void WarrensTest()
        {
            
            SPFile myFile = ???????????????? .ListItem.File;
            myFile.Properties["debugmsg"] = myFile.Properties["MailTo"].ToString();
            myFile.Update();
 
        }
}

Open in new window

warrenrapsonAsked:
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;
0
 
lionel_barreCommented:
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.
0
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.