0

Im trying to figure out how can I edit the default.aspx page. Where the default.aspx for the root web is stored ?

And how can i programmatically add a webpart to it?

What is the diference in using Modules to store pages X using _Layout directory?

Thank you

0

There may be times when you may want to deploy files to the SharePoint server regardless of their file type, such as new master pages. To do this, you can use Modules (not to be confused with Visual Basic code modules). Modules are containers for files in a SharePoint solution. When the solution is deployed, the files in the module are copied to the specified folders on the SharePoint server.

http://msdn.microsoft.com/en-us/library/ee231567(v=vs.100).aspx

all about webparts that you would need to know~!

http://msdn.microsoft.com/en-us/library/ee231579.aspx

adding a webpart to a page is complex:

    public void AddWebPartToPage(SPWeb web, string pageUrl, string zoneID, int zoneIndex)
    {
        using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
        {
                VisualWebPart1.httpRedirectHome.httpRedirectHome redirectme = new VisualWebPart1.httpRedirectHome.httpRedirectHome();
                manager.AddWebPart(redirectme, zoneID, zoneIndex);

        }
    }

the above is a method i made to add a webpart to a given page...

to understand what im doing! VisualWebPart1.httpRedirectHome.httpRedirectHome that is my visual webpart that im creating in a new object:

so create your visual webpart.

if you were to create a feature that is in the same project and have an event handler attached to it, within the event you call that method:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    { 
        //when the feature is activated call this method
        using (SPSite site = new SPSite(SPContext.Current.Site.Url))
        {
           using (SPWeb web = site.OpenWeb())
           {
              //get the current web object to pass along, give the url, its webpart zone and its zone index
              AddWebPartToPage(web,SPContext.Current.Site.Url + "/mysubsite/default.aspx",0,"Main",0)
           }
        }
    }

    public void AddWebPartToPage(SPWeb web, string pageUrl, string zoneID, int zoneIndex)
    {
        using (SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(pageUrl, PersonalizationScope.Shared))
        {
                VisualWebPart1.httpRedirectHome.httpRedirectHome redirectme = new VisualWebPart1.httpRedirectHome.httpRedirectHome();
                manager.AddWebPart(redirectme, zoneID, zoneIndex);

        }
    }

SPLimitedWebPartManager

Provides a limited set of Web Part operations that can be performed in object model scenarios when there is no HttpContext and no instantiated Page object.

http://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.webpartpages.splimitedwebpartmanager_members.aspx

1
  • lol its fine! happy to help!
    – Ali Jafer
    Dec 6 '13 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.