For replacing default.aspx with your custom file, in feature activation receiver, place the following code:
SPFile newDefaultPage = // get your custom default page from somewhere
SPFile defaultPage = web.RootFolder.Files["default.aspx"];
// saving backup
defaultPage.CopyTo("default-old.aspx", true);
// copying our custom page over the default
newDefaultPage.CopyTo("default.aspx", true);
Similarly, in the page deactivation handler, you can restore the page from the default-old.aspx
file.
Update: if you want to activate this feature on site collection scope, and then replace the default.aspx files on all the sites in site collection except root site, you can achieve this using following code:
var site = (SPSite)properties.Feature.Parent;
foreach (SPWeb web in site.AllWebs)
{
if (web.IsRootWeb)
continue;
try
{
ReplaceDefaultAspx(web);
}
finally
{
web.Dispose();
}
}
Where ReplaceDefaultAspx method contains the first piece of code.