SharePoint: How to add news listings to the News Area thro’ programmatically

I compiled a sample piece of code snippet to add news listings to the news area.

 

            //Site object

            SPSite site = new SPSite("https://karthickmain:9090");

            //Get the portal context

            PortalContext context = PortalApplication.GetContext(site.ID);

            //Get the news area guid

            Guid newsGuid = AreaManager.GetSystemAreaGuid(context, SystemArea.News);

            //Get the new area

            Area newsArea = AreaManager.GetArea(context, newsGuid);

            //Get the area listing collection

            AreaListingCollection objALC =  newsArea.Listings; 

            //Add the news to the listing

            AreaListing objAL =   objALC.AddListing("Program100" ,"dd",ListingType.News, "",null);

            //Set the the html to display the content

            objAL.HtmlBlob = "<b>hello world </b> asdfasdf <b><i>Hello World";

            //Set the image file url

            objAL.LargeIconUrl ="https://karthickmain/newsitm2.gif" ;

            //Set the description

            objAL.Description = "hello world";

            //Set the url for the news

            objAL.URL = site.Url + "/txtlstvw.aspx?LstID=" + objAL.ID;

            //Update the list collection

            objAL.Update();

Comments