Logo 
Search:

Sharepoint 2010 Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint 2010       RSS Feeds

Displaying webpart through site definition.

  Asked By: Aftab    Date: Sep 09    Category: Sharepoint 2010    Views: 2103

Hi there,

This seems to be a good forum. I have a working Team site, and I would like to place my custom webpart control on the page which will display a simple list.

I am using a Site definition and have the Onet.xml file to customize my team site. To make the webpart appear, I think we add the custom webpart code to the Modules element in the Onet.xml file. But just can't make my webpart to show up on the Team site.

How can we make the custom webpart to display thru the Onet.Xml file configuration.

Kindly advice,

Thank you!

sincerely,
aftab

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Dennis Tjassens     Answered On: Oct 26

[off topic]use webtemplates instead of sitedefinitions.[/off topic]


SPSite site = new SPSite("http://siteurl");
SPWeb web = site.RootWeb;
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("Shared Documents/NameOfMyPage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

//Create an instance of Custom Webpart and add in a Webpart zone
MyWebPart.MyPart wp = new MyWebPart(); // your custom webpart instance
wp.Title = "My WebPart"; // set properties


webParts.AddWebPart(wp, "Left", 0);
webParts.SaveChanges(wp);



 
Didn't find what you were looking for? Find more on Displaying webpart through site definition. Or get search suggestion and latest updates.




Tagged: