Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

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.

share|improve this answer
    
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 Dinero Oct 13 '10 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). –  James Love Oct 13 '10 at 16:16
add comment

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); }

share|improve this answer
    
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 Dinero Oct 16 '10 at 16:31
add comment

You could create a new Site Template with the exact layout you need and provision your new site from that template.

share|improve this answer
    
I don't know how to do that yet. –  Bob Dinero Oct 13 '10 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.