1

We have just migrated to SP2019 on-prem from SP2010 and are in the middle of customizing it for our needs. I have a requirement to modify the waffle menu to remove the OneDrive link. We don't use OneDrive corporately and they don't want people seeing it or even going in there to poke around.

I used this post I found on reddit: https://www.reddit.com/r/sharepoint/comments/acd0mb/how_to_remove_sharepoint_and_onedrive_from_waffle/ and the link provided for https://www.experts-exchange.com/articles/6250/SharePoint-2010-Programmatically-Add-JavaScript-Meta-Tags-and-CSS-Styles-to-the-Header-of-Every-Page.html to create a custom solution to inject some CSS in a User Control.

This has mostly worked, it's hidden when I browse our intranet pages and also when I go to My Site (http://mysite/person.aspx). However, the OneDrive link is still visible when browsing some pages. For instance, Site Settings page (http://contoso/site/_layouts/15/settings.aspx?Source=blah) has it hidden but any Site Contents (http://contoso/site/_layouts/15/viewlsts.aspx?view=14) page the OneDrive link is still visible. On the My Site side, as I mentioned if I go to my page then it is hidden but if I go to the SharePoint home page ( http://mysite/_layouts/15/sharepoint.aspx ) then it is still visible.

It seems like my UserControl is only loading for specific pages and not everything as I would have expected.

Did I miss anything? I followed the steps from https://www.experts-exchange.com/articles/6250/SharePoint-2010-Programmatically-Add-JavaScript-Meta-Tags-and-CSS-Styles-to-the-Header-of-Every-Page.html but I skipped the steps for the JavaScript and CSS files, and this is what my ascx.cs file looks like:

using System;
using System.Web.UI;
using Microsoft.SharePoint;

namespace WaffleHider.CONTROLTEMPLATES.WaffleHider
{
public partial class UserControl1 : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
string SiteURL = SPContext.Current.Web.Url;
//this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "custom.js", SiteURL + "/_layouts/WaffleHider/custom.js",true);
}
protected override void OnInit(EventArgs e)
{
Page.Init += delegate (object sender, EventArgs e_Init)
{
//string SiteURL = SPContext.Current.Web.Url;
//Page.Header.Controls.Add(new LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + SiteURL + "/_layouts/WaffleHider/custom.css\" />"));
//Page.Header.Controls.Add(new LiteralControl("<meta name=\"keywords\" content=\"sharepoint,c-sharp\" />"));
};

base.OnInit(e);
}
}
}

This is my elements.xml file:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="AdditionalPageHead"
Sequence="12"
ControlSrc="~/_CONTROLTEMPLATES/15/WaffleHider/WaffleHider.ascx" />
</Elements>

This is what my UserControl file looks like:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WaffleHider.ascx.cs" Inherits="WaffleHider.CONTROLTEMPLATES.WaffleHider.UserControl1" %>

<style>
a[id$=AppTile_Documents] {
display: none !important;
}
</style>

The feature is targeting the web app, and it is activated in both the intranet web app as well as the My Site web app. No errors on deployment. I first tried to use the custom.js file to use Jquery to hide the OneDrive menu item but for whatever reason I could never get the custom.js to actually be included in the , the closest I got was that it seemed to have loaded but at the very top of my pages it just said the file path of the JS file and didn't actually execute anything.

I'm happy with the CSS in the UserControl itself as it is mostly working I just need to get it to apply everywhere. I suspect there may be some interference in the branding solution we got from a consulting company.

  • Did you try adding the above piece of css code in the site collection and mysites master pages ? if that works, then we can have a powershell script to apply our custom master pages to all the site collections. – Karthik Jaganathan Jan 31 at 12:38
  • 1
    The modern sites don't use master pages, so unfortunately that would not solve the issue. Thanks though – Arin Zandbergen Feb 4 at 17:49
3
+100

The reason the CSS is not correctly applied is, that the pages you are referring to are rendered using the new modern experience in SharePoint 2019. The problem with it is, that CSS injected as a delegate control (like yours) are ignored on this kind of page. There is practically no easy way to inject CSS directly into the page. But since you are on-premises there might be a few ways around it.

For example, the suite navigation includes the "SuiteNav.css" file from the hive (16\Template\Layouts\1033\Styles\SuiteNav.css). Appending a CSS rule here will also include it in the modern experience. However, modifying SharePoint elements directly in the hive is not exactly supported and not really maintenance friendly as it needs to be done on each frontend-server and is likely to be overwritten by future updates.

There might also be somewhat supported way: Instead of modifying a part of SharePoint directly, you can "clone" the default "SuiteNav.css" and deploy it to all servers using a farm solution (you can use the one you've already got). Then, you could install an URL Rewrite module on IIS that will be used to redirect requests to the original "SuiteNav.css" to your custom one. Such redirects appear to be supported (https://support.office.com/en-us/article/supportability-of-rewrites-and-redirects-in-sharepoint-2016-2013-2010-and-2007-a74a19f2-a59a-4b39-8be4-ce63e50139fa). Out of interest, I also researched whether the URL rewrite module can be used to add contents to the response body, which would not require deploying a custom CSS file first, see https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-outbound-rules-to-add-web-analytics-tracking-code.

I've only tested modifying the SuiteNav.css directly to find out whether this approach has a chance of succeeding. When it comes to the best way to utilize it, I'm not sure how far you are willing to go, to implement this change and what would be required to make this bullet-proof or easy to install. For example

  • the IIS rewrite module must first be installed (it is not included by default)
  • the rules might be stored in the web.config file of each web-application, which might also be overridden not just in case of an update, but also if you change settings for the web-application in the central administration.
  • I've found that SharePoint has a "Kill-Switch" internally, which determines whether the CSS is actually included or not. I believe it is only there to deactivate it in a cloud-environment and is not meant to change in the future.
  • Also, if you are down the rabbit hole of redirect SharePoint requests you could also intercept the REST call that produces the contents of the waffle menu ( "_api/Microsoft.SharePoint.Portal.SuiteNavData.GetSuiteNavData"), which is a bit more complicated but would also be an interesting approach.

Also, you can inject CSS using an SPFX application customizer (as seen here https://github.com/SharePoint/sp-dev-fx-extensions/tree/master/samples/react-application-injectcss), but I find it a bit much just so you can have some CSS on your page.

  • Thank you. Your explanation of why the CSS from UserControl is not applied on those pages makes sense, it's what I was afraid of. I will explore some of your suggestions. Thanks! – Arin Zandbergen Feb 4 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.