Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Event Receiver to update list with Page Title and Author

$
0
0

Hi,

I have written an event receiver so that

If any page is created under Pages Library,page tile and Author should be updated in a list.

For this I have created a custom list PagesList with column PageTitle as single line of text,column Author as single line of text.

Attached break point ItemAdded event,but isn't hitting after creating page under Pages Library.

Below code has been written to achieve, but not working as expected.

Please let me know if I am making any mistake here.

public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            //System.Diagnostics.Debugger.Launch();
             SPListItem item = properties.ListItem;
            using (SPSite objsite = new SPSite(SPContext.Current.Site.Url.ToString()))
            {
                using (SPWeb objweb = objsite.OpenWeb())
                {
                    SPList objlist = objweb.Lists.TryGetList("PagesList");
                    SPListItem newitem = objlist.Items.Add();
                    newitem["PageTitle"] = item.Title;
                    newitem["Author"] = item.Fields["Created By"];
                    newitem.Update();
                }
                
            }
        }

Regards,

Sudheer


Thanks & Regards, Sudheer


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>