0
  public override void ItemAdded(SPItemEventProperties properties)
    {
        try
        {
            base.ItemAdded(properties);
            EventFiringEnabled = false;

            SPListItem item = properties.ListItem;
            item["colmn1"] = properties.Web.Title;
            item["colmn2"] = properties.ListTitle;
    }

I am adding this code for updating a metadata of my document library. I am not using Synchronous event. So whenever I am uploading a document the Modified By column is replaced by Site Collection Admin ID not the current logged in user ID.

How to get the current logged in user in the modified by column. I can not use SPUser user = properties.Web.EnsureUser("domain\\username"); because I have to get the current logged in user dynamically.

2
  • I am not quite sure what you want to retrieve. Do you need the user that added the item? This you can get with var user = properties.Web.CurrentUser;. But maybe I misunderstood your question. Apr 28, 2015 at 14:02
  • @Dolgs thanks,I want to update the modfied by column with the current logged in user name.currently its been replaced by site collection's admin name.How can I get the current loggedin user name
    – samolpp2
    Apr 28, 2015 at 14:35

2 Answers 2

1

This is because you are Modifying the item in ItemAdded event. This basically updates the Modified By to the context of the Process which executes the event.

What should change your logic to get the Modified User into a temporary object and then use that while updating the item.

2
  • Thanks! Here the temporary user is current logged-in user.I want to get his/her ID. So I need to get the current loggedin in user id.Is there any way to get that.
    – samolpp2
    Apr 28, 2015 at 15:41
  • @SaMolPPp it will be in Modified By Field. Read it before you do the update. Apr 28, 2015 at 15:42
0

Use this Code...!

using(SPSite originalsite = new SPSite(properties.SiteId,properties.OriginatingUserToken)){//To get the current user 
using (SPWeb web = originalsite.OpenWeb()){string strUserName = web.CurrentUser.LoginName.ToString();}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.