I need to modify the content of the default.aspx page of over 100 SharePoint 2010 sites to make a slight change in the content of the page.
Because of the number of sites, I would like to do it programmatically, either in PowerShell, or through programming a console application or something along those lines.
I've found plenty of sites/blogs that describe how to look up the default page in the pages library, but that doesn't work for me as even though the sites have the publishing feature activated, there're no files in the Pages library, and as far as I can tell it's not a wiki page.
The issue I'm trying to fix is that in the ListViewXml tag of lists on the homepage isn't formed right. It has two ?'s (Query strings) in the url, and I just want to replace every instance of "?RootFolder=" to "&RootFolder="
So far I've tried running a c# console and I've been able to locate the default.aspx file, but the content I get isn't all of the content, just the structure.
using (SPSite siteCollection = new SPSite("my_site_url"))
{
SPWebCollection sites = siteCollection.AllWebs;
foreach (SPWeb site in sites)
{
try
{
SPFile file = site.GetFile(site.Url + "/default.aspx");
System.IO.Stream myStream = file.OpenBinaryStream();
System.IO.StreamReader reader = new System.IO.StreamReader(myStream);
string text = reader.ReadToEnd();
Console.WriteLine(text);
}
finally
{
if (site != null)
site.Dispose();
}
I'm just outputting the text to the console for testing purposes. I'm hoping that I can just do a string replace, and the write the content back to the file and save it somehow.
The solution doesn't have to be in C#, I just need some automated way of making the changes over many site home pages and this seemed like the route with the most promise. Currently I'm manually opening the page in SharePoint Designer, doing a find replace and then clicking the save button, which is very tedious.