About Me

My photo
a Dynamic and Energetic guy.....

Sunday, September 28, 2008

Add Sharepoint OOB SummaryLinkWebPart Programatically

protected override void CreateChildControls()

{
if(!_error)
{

try

{
base.CreateChildControls();
//EnterpriseAnnouncement webpart

SPWeb
web = SPContext.Current.Web;
SPList
enterpriseNoticeList = web.Lists[EnterpriseNoticeBoardUrlName”];
SPQuery
query = new SPQuery();
SPListItemCollection
collection = enterpriseNoticeList.GetItems(query);

if(collection != null)

{
SummaryLinkWebPart
announcementWP = new SummaryLinkWebPart();
announcementWP.Title = ConfigurationInfo.AnnouncementsListDisplayName;
int counter = 0;

foreach (SPListItem item in collection)

{
try
{
announcementWP.SummaryLinkValue.SummaryLinks.Add
(new SummaryLink(item["Title"].ToString()));

announcementWP.SummaryLinkValue.SummaryLinks[counter].LinkUrl = http://www.google.lk;
//
EnterpriseAnnouncement
item[“URL”].ToString();

announcementWP.SummaryLinkValue.SummaryLinks[counter].OpenInNewWindow = true; announcementWP.SummaryLinkValue.SummaryLinks[counter].Description = item["Comments"].ToString(); announcementWP.SummaryLinkValue.SummaryLinks[counter].Style = "Image on left";
announcementWP.SummaryLinkValue = announcementWP.SummaryLinkValue;
counter++;

}

catch(Exception ex)

{
}


}
this.Controls.Add(announcementWP);

}

else

{}

}

catch(Exception ex)

{
}

}
}

No comments:

My Masters