Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 623
  • Last Modified:

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

0
warrenrapson
Asked:
warrenrapson
2 Solutions
 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now