Monday, November 21, 2011

Adding Webparts in Sharepoint Using Code

using (SPSite spSiteTest = new SPSite(“SiteURL”) 
 {   
   using (SPWeb spWebTest = spSiteTest.OpenWeb())   
   {     
     SPWebPartCollection webparts = 
     spWebTest.GetWebPartCollection("WebPageURL",Storage.Shared);      
     //create new webpart object            
     WebPartToBeAdded wpNew = new WebPartToBeAdded();      
     //set properties of new webpart object     
     wpNew.ZoneID = "WebPartZoneIDWhereWebPartIsToBeAdded";     
     wpNew.Title = "Web Part Title";     
     wpNew.ChromeState = 
     System.Web.UI.WebControls.WebParts.PartChromeState.Normal;     
     wpNew.ChromeType = 
     System.Web.UI.WebControls.WebParts.PartChromeType.None;      
     //add new webpart object to webparts collection     
     webparts.Add(wpNew);      
     //update spWeb object     
     spWebTest.Update();     
   } 
 } 

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

The Code 39 error occurs when Windows is unable to load the device driver for a specific hardware device. This typically indicates that the driver is corrupted, missing, or incompatible

The Code 39 error occurs when Windows is unable to load the device driver for a specific hardware device. This typically indicates that the...