Pages

Sunday 26 May 2013

How to flush invalid SPWebConfigModifications SharePoint 2010


Occasionally you modify the web.config using the SPWebCongiModification class. Some times the config entries are not removed from the web.config. You can use the code below to exactly do this:

This is an exact copy of the code mentioend by Luis:
http://stackoverflow.com/questions/10732808/how-to-flush-invalid-spwebconfigmodifications

This is for my reference and I take no credit for this solution, 100% credit goes to Luis :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;

namespace ModTool
{
    class Program
    {
        static void Main(string[] args)
        {

            SPSite site = new SPSite(args[0]);
            SPWebService service = site.WebApplication.Farm.Services.GetValue<SPWebService>();


            if (args.Length == 1 || string.IsNullOrEmpty(args[1]))
            {
                Console.Out.WriteLine("Listing all Mods and Owners");
                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    Console.Out.WriteLine("Mod:" + mod.Name + ", Owner:" + mod.Owner);
                }
            }
            else
            {
                Console.Out.WriteLine("Removing all mods owner:" + args[1] + ", reference site:" + args[0]);

                List<SPWebConfigModification> toDelete = new List<SPWebConfigModification>();

                foreach (SPWebConfigModification mod in service.WebConfigModifications)
                {
                    if (mod.Owner == args[1])
                    {
                        toDelete.Add(mod);
                    }
                }

                Console.Out.WriteLine("Found " + toDelete.Count + "Mods");



                foreach (SPWebConfigModification mod in toDelete)
                {
                    service.WebConfigModifications.Remove(mod);
                }
                service.Update();
                SPWebService.ContentService.ApplyWebConfigModifications();
                Console.Out.WriteLine("Done!!");
            }
        }
    }
}
 
Usuage:
ModTool http://site - List all the mods for the farm, site is just an entry point
ModTool http://site owner -Deletes all the mods for in the farm forwhich the owner is "owner" 




Thursday 16 May 2013

The Security validation for this page is invalid. Click back in your web browser, refresh the page and try your operation again. After installing April 2013 CU for SharePoint server 2010

After installing the April 2013 CU for SharePoint Server 2010. InfoPath forms were throwing the following error:










MS have acknowledged that this issue was introduced by the April 2013 CU, A critical on demand (COD) will be available shortly.

I will update the post with the COD.

Monday 13 May 2013

How to create a new host named site collection in its own content database using Powershell


Step 1:  Add New Content Database to the Web Application
New-SPContentDatabase -Name <content_db_name> -WebApplication <web application URL>


Step 2: Get a reference to the hostnamed web application:
$webApp = Get-SPWebApplication "MyHostNamedWebApp" 
 
Step 3: Create a site collection 
new-spsite http://sharepointDev.com -ownerAlias "domain\user" -HostHeaderWebApplication $WebApp -ContentDatabase "WSS_Content_Dev_test" -template sts#0

Tuesday 7 May 2013

BCS Throttle Management - SharePoint 2010

In order to check theBCS item limit run the following command:

$bdcProxy = Get-SPServiceApplicationProxy | where {$_.GetType().FullName -eq ('Microsoft.SharePoint.BusinessData.SharedService.' + 'BdcServiceApplicationProxy')}
  
$dbRule = Get-SPBusinessDataCatalogThrottleConfig -Scope Database -ThrottleType Items -ServiceApplicationProxy $bdcProxy


Result:
Scope: Database
ThrottleType: Items
Enforced: True
Default : 3000
Max: 1000000



Reference:
http://blogs.msdn.com/b/bcs/archive/2010/02/16/bcs-powershell-introduction-and-throttle-management.aspx 

Monday 6 May 2013

Manage Visual Upgrades in sharePoint 2010

If you have a big site collection and some of the sub sites have not been upgraded to the UI version 4, then this powershell script will help:

# Gets the UI for each site in the


#create a txt file
"SitePath, SWebPath, UIVersion, UIVersion Configuration Enabled, MasterURL, Custom Master URL" > "UI-Version.txt" #Write the Headers in to a text file

$sc = Get-SPSite http://www.mySiteCollection.com; $sc.GetVisualReport() | Select-Object "SitePath", "SWebPath", "UIVersion", "UIVersion Configuration Enabled", "MasterURL", "Custom Master URL" >> UI-Version.txt

Restore a deleted site collection using PowerShell

In order to delete a sub site, one can recover using admin recyclebin. You can restore a sub site which has been deleted using the UI not SharePoint designer. But if you have to recover a site collection then you will need to use powershell.

Thanks to  Salaudeen Rajack


Get-SPDeletedSite - Displays list of sites deleted. 
Restore-SPDeletedSite - Restore a deleted site 
Remove-SPDeletedSite - To permanently remove the deleted site collection.

Permanently remove the deleted site collection:
Get-SPDeletedSite -webapplication http://sharepoint.company.com | Remove-SPDeletedSite

Wednesday 1 May 2013

How to get the SharePoint farm configuration

Occasionally you would want to get the entier SharePoint Farm configuration. Well, there is this awesome Executable on codeplex which just does this:

http://spsfarmreport.codeplex.com