Friday, April 27, 2012

Restored SharePoint site extremely slow after 2010 visual upgrade

This morning I migrated one of the older Contoso sites to my local development virtual machine and did the visual upgrade to 2010 to start working on some new exciting developments only to find the site is dead slow, at first I thought it was my resources, so I restored the site to a different server where all was fine until I did the visual upgrade on it, then experienced the same thing.

I started working like that but got very frustrated very fast and decided to investigate the issue.

I noticed that this happens every time the context changes or the ribbon reloads, it was almost as if the ‘freezed’ along with all other SP functions until it was done loading and then things would be fine again. While staring at this phenomena I saw the Contoso logo was missing till the last second and then only displayed the ugly red cross associated with image not found, frustrated and being pedantic about things like that (not to mention the luck factor) I figured I can just as well quickly fix that first…


And then it all made sense, the image's URL was hardcoded to the old server name. FAIL!!!

I changed it to point to _layouts after which everything was as good as new, so my suspicion is that the ribbon and all associated functionality was being holdup until it timed out trying to reach the server as my VM was not on the domain.

Tuesday, April 17, 2012

Global Assembly Cache (GAC)

The Global Assembly Cache (GAC) is a machine-wide .NET assemblies cache for Microsoft's CLR platform. The approach of having a specially controlled central repository addresses the shared library concept and helps to avoid pitfalls of other solutions that led to drawbacks like DLL hell. - wikipedia

Note: 'c:\windows\assembly' consists of subfolders like 'GAC, GAC_32, GAC_MSIL, GAC_64...' that contain the dll's but win shell stops you from browsing to it.



So you don't have Gacutil.exe or afraid to use it here is some alternative to get dll's in and out of the GAC.

1. Map the assembly as a drive in windows explorer.
'\\[machine name]\c$\windows\assembly'

2. Run cmd as admin and type start full gac path you want
'start %windir%\assembly\GAC_MSIL\'

Saturday, April 7, 2012

Hide meeting workspace default templates

After creating a whole arsenal of nice new custom meeting workspace templates for Contoso, business decided thy no longer want to confuse end-users with the default templates and only want them to be able to pick the custom ones when scheduling meetings from outlook and the web front end. The following code will hide all meeting workspace templates containing 'meeting workspace' in their name.
namespace Contoso.HideMeetingWorkspace.Features.HideDefaultMeetingWorkspaceFeature
{
    using System;
    using System.Collections.ObjectModel;
    using System.Runtime.InteropServices;
    using Microsoft.SharePoint;

    [Guid("00000000-0000-0000-0000-000000000000")]
    public class HideDefaultMeetingWorkspaceFeatureEventReceiver : SPFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = properties.Feature.Parent as SPWeb)
            {
                SPWebTemplateCollection existingWebTemps = web.GetAvailableWebTemplates(1033);
                Collection newWebTemps = new Collection();
                for (int i = 0; i < existingWebTemps.Count; i++)
                {
                    if (!existingWebTemps[i].Title.ToLower().Contains("meeting workspace"))
                    {
                        newWebTemps.Add(existingWebTemps[i]);
                    }
                }

                web.SetAvailableWebTemplates(newWebTemps, 1033);
                web.Update();
            }
        }

        // Uncomment the method below to handle the event raised before a feature is deactivated.
        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = properties.Feature.Parent as SPWeb)
            {
                web.AllowAllWebTemplates();
                web.Update();
            }
        }

        // Uncomment the method below to handle the event raised after a feature has been installed.
        // public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        // {
        // }

        // Uncomment the method below to handle the event raised before a feature is uninstalled.
        // public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        // {
        // }

        // Uncomment the method below to handle the event raised when a feature is upgrading.
        // public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary parameters)
        // {
        // }
    }
}

Note: This is most definitely not the best written code nor does it cater for 100% of scenarios, but if you’re in a pinch and need a fast fix this should be more than enough to get you started.