Monday, October 27, 2008

Adding the Recycle Bin to "Site Actions"

In a previous post I pointed on how to hide the recycle bin icon from the SharePoint site web page.

Now I'll create a merge between that and sending the Recycle Bin icon (with link) to the Site Actions drop down menu.
To achieve this I created a SP Feature called HideRecycleBin in order to have the chance to enable/dissable it depending on Sites/Subsites:

Feature.xml





Elements.xml





HideRecycleBin.css





HideRecycleBinReceiver.cs



using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Diagnostics;
using System.IO;

namespace CustomFeatures.HideRecycleBin
{
class HideRecycleBinReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = (SPWeb)properties.Feature.Parent;
SPFile coreFile = web.Folders["Shared Resources"].Files["custom.css"];
coreFile.CopyTo("Shared Resources/customCSS-archive-HideRecycleBin.css", false);

SPFile customFile = web.Folders["Shared Resources"].Files["HideRecycleBin.css"];
customFile.CopyTo("Shared Resources/custom.css", true);
}
catch (SPException x)
{
logMessage(x.Message, EventLogEntryType.Error);
}
catch (Exception x)
{
logMessage(x.Message, EventLogEntryType.Error);
}
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
try
{
SPWeb web = (SPWeb)properties.Feature.Parent;
SPFile customFile = web.Folders["Shared Resources"].Files["customCSS-archive-HideRecycleBin.css"];
customFile.CopyTo("Shared Resources/custom.css", true);

SPFile HideRecycleFile = web.Folders["Shared Resources"].Files["HideRecycleBin.css"];
customFile.Delete();
HideRecycleFile.Delete();
}
catch (SPException x)
{
logMessage(x.Message, EventLogEntryType.Error);
}
catch (Exception x)
{
logMessage(x.Message, EventLogEntryType.Error);
}
}

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
logMessage("View Hide Recycle Bin Site Action feature installed", EventLogEntryType.SuccessAudit);
}

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
logMessage("View Hide Recycle Bin Site Action uninstalling", EventLogEntryType.Information);
}

private void logMessage(string message, EventLogEntryType type)
{
if (!EventLog.SourceExists("SharePoint"))
EventLog.CreateEventSource("SharePoint", "Application");
EventLog.WriteEntry("SharePoint", message, type);
}
}
}

Manifest.xml



Hidding the Recycle Bin in SharePoint

Working on customizing SharePoint lately? Needed to remove the recycle bin?

You just need to copy this code snippet into the .css that the web page is using:

#ctl00_PlaceHolderLeftNavBar_idNavLinkRecycleBin
{
Visibility:hidden;
}

and voilá, the recycle bin is not there anymore.

In a next post I'll explain how to create the Recycle Bin link in the "Site Actions" drop down list.