I've created a Visual Studio SharePoint 2010 solution with an ASCX that adds some JavaScript files and CSS to the head of each page; this is based on this article. When I deploy the solution, it adds the files to the correct server folder:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\CustomPageHead
But then the files aren't added to the page headers. I've gone in and activated the user control from the site features but this hasn't fixed it. Here's the simple code in the CustomPageHead.ascx.cs file; I removed the JS files to see if that was causing the issue:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
namespace CustomPageHead.CONTROLTEMPLATES
{
public partial class CustomPageHead : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
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/CustomPageHead/custom.css\" />"));
Page.Header.Controls.Add(new LiteralControl(
"<meta name=\"keywords\" content=\"sharepoint,c-sharp\" />"));
};
base.OnInit(e);
}
}
}
Could it be that I'm trying to activate the feature from a site such as http://mydomain.org/mysite/ and the path in the code above is looking at the current site's root? But why isn't it at least adding the control to the page, even if it has the wrong path?