|
Post by shmeric on Nov 11, 2009 17:52:25 GMT -6
I understand how to create a web part page using sharepoint's nifty UI....i.e.:
- go to site actions > create > web part page
- On the 'New Web Part Page' form: give it a name, select a 'layout template', and choose a document library for it to go into to...then click create.
- On the 'edit mode' form for you new web part page: add web parts and select the appropriate options for each web part.
I need to do all of and exactly this....however I need to do it programmatically as a part of a sharepoint application page (in the code behind the application page, obviously)...in WSS 3.0.
I understand that it's possible to do this as a feature that can be added to a sharepoint site (haven't looked at the details here tho).
This doesn't work for me cuz the web part page needs to be generated dynamically (due to the fact that document libraries get generated dynamically). For context: I'm building a web part page the has several related lists (of various sorts) on one page.
Seems like this wouldn't be that uncommon a thing to do, but haven't seen anything written up about it. Is there something written that I've missed? Or does anyone have any helpful suggestions/hints for me?
thanks
|
|
alina
Limited Experience
Posts: 126
|
Post by alina on Jul 24, 2012 23:30:04 GMT -6
You can add webparts by using the SPLimitedWebPartManager and your webPart defininition URL. This example should get you started:
XmlTextReader reader = new XmlTextReader(new StringReader(web.GetFileAsString(<Url to your .webpart file here>)));
SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(<URL to your page>, Syste.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
WebPart wp = (WebPart) wpm.ImportWebPart(reader, out errMsg); wp.Title = "My Title for this webpart";
wpm.AddWebPart(wp, <Name of WebpartZone here, e.g. "Header">, <Zone Index here>); wpm.SaveChanges(wp);
|
|