I am using Parentweb.Webs.Add to add subsite. However the default.aspx comes with sharepoint log which I dont need. Also I need to move the announce webpart zone to the right. And delete calendar webpart. How do I do this programatically (not sharepoint designer)? I like to modify the page right after the creating the subsite.
3 Answers
If you interrogate the SPWebPartManager for that page once it's been provisioned, you can mess around with the web parts on the page.
-
James, 1. What do you mean by "Provisioned"? 2. I am using following code but not working using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(file.ServerRelativeUrl, PersonalizationScope.Shared)) wpm.MoveWebPart(wpm.WebParts.["Annoucements"], "RightColumn", 1);– Bob DineroCommented Oct 13, 2010 at 14:36
-
You have a fullstop between "WebParts" and ["Announcements]" which shouldn't be there, what other error messages are you getting? By Provisioned, I mean fully created and ready to load - if you want to modify this right after creating the subsite you will have to watch out for race conditions as you might end up with the scenario where you're trying to edit a page that hasn't been created yet (some operations are asynchronous). Commented Oct 13, 2010 at 16:16
Now no errors with this code but It does not move the webpart to right side.
using (SPLimitedWebPartManager wpm = web.GetLimitedWebPartManager(file.ServerRelativeUrl, PersonalizationScope.Shared))
{
List webparts = new List();
foreach (Microsoft.SharePoint.WebPartPages.WebPart webpart in wpm.WebParts)
{
if (webpart.Title == "Announcements")
{
wpm.MoveWebPart(webpart, "RighColumn", 2);
}
}
//wpm.MoveWebPart(wpm.WebParts["Announcements"], webpartzone, 1);
}
-
It seems that the code could never get hold of the default.aspx file therefore no change is being made to the page. oh well, i will just do it manually. bummer– Bob DineroCommented Oct 16, 2010 at 16:31
You could create a new Site Template with the exact layout you need and provision your new site from that template.
-
I don't know how to do that yet.– Bob DineroCommented Oct 13, 2010 at 18:27