Thursday, May 8, 2014

A field Update on drag and drop of Document Library using Event Receiver

A field Update on drag and drop of Document Library using Event Receiver


 Actually, i had a chance to update a field in document library using event receiver. I have used the synchronous method on event receiver to update an item in list. We need to write a code on ItemAdding method of event receiver. So we need to choose the "Item being added" in Event receiver type. Then do the code as below i mentioned.

 public override void ItemAdding(SPItemEventProperties properties)
        {
            base.ItemAdding(properties);
            if (properties.ListTitle == "Library Name")
            {
              

                    string strField = properties.List.Fields["FieldName"].InternalName;
                    properties.AfterProperties[strField] = "12346";
                    properties.Web.Update();
                   
            }
        }

That's all. Then deploy the solution and enjoy.

Happy Coding ... !!!!!

No comments:

Post a Comment