Showing posts with label MasterPages. Show all posts
Showing posts with label MasterPages. Show all posts

Wednesday, 4 March 2009

Adding Metadata to a MOSS 2007 Publishing Portal pt2

Add three columns to the Content Type that you use for WCM. In this example I've used PageTitle, PageDescription and PageKeywords.

Add the assembly to the Master Page and reference the MetaData dll
<%@ Register TagPrefix="metaControl" Namespace="MetaData.Render" Assembly="MetaData.Render, Version=1.0.0.0, Culture=neutral, PublicKeyToken=198d2f392e054e3e" %>

Example: In the head
<metaControl:SharePointMetaTag runat="server" ID="metaTag1" MetaName="DESCRIPTION" MetaAttributeName="Content" PublishingPagePropertyName="PageDescription" DefaultAttributeContent=""/>


The DefaultAttributeContent is where the editor has not completed the field as we've made them non manditory

namespace MetaData.Render
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
// using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

///
/// A webpart to render MetaData information onto a published page
///

[ParseChildren(false), ToolboxData("<{0}:MetaTag runat=\"server\" name=\"\"> "), PersistChildren(true),
AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal),
DefaultProperty("Name")]
public class MetaData : WebControl
{
///
/// Name to render out
///

private string name;

///
/// Initializes a new instance of the MetaData class.
///

public MetaData() : base(HtmlTextWriterTag.Meta)
{
}

///
/// Gets or sets the Tag name to render out
///

[Bindable(true), Category("Appearance"), DefaultValue(""), Description("Sets the MetaTag's name attribute.")]
public string Name
{
get { return this.name; }
set { this.name = value; }
}

///
/// Render the control
///

/// Render this writer
protected override void Render(HtmlTextWriter writer)
{
// Render control only if there is a tagname specified
if (!this.name.Equals(string.Empty))
{
base.Render(writer);
}
}

///
/// Add attributes to Render
///

/// The writer to add the attributes to
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
// Write the name attribute
writer.AddAttribute("name", this.name);

// Write the value attribute
StringWriter sw = new StringWriter();
base.RenderContents(new HtmlTextWriter(sw));
writer.AddAttribute("value", sw.ToString());
}

///
/// Render the content out
///

/// The writer to be rendered
protected override void RenderContents(HtmlTextWriter writer)
{
// this control does not render any contents
}
}
}

Thursday, 8 May 2008

More Deployment Issues

Having struggled with this for what seems like an eternity - and has since resulted in the project being put back by some considerable margin - it was reading through some more blogs that I came across what seemed to be the solution to the Masterpage problem (see previous posts).

By developing a feature that will create a site based upon a specific Masterpage and have it deploy correctly, the feature creation was OK and seemed to work but the associated contentTypes I could get to be created at the same time. After a lot of time yesterday the feature installed, but only at a site level because if the scope is changed to 'Farm' or 'Web' it would not install. So with this in mind I copied the relevant files to the WFE and installed/activated the feature. Created a new site on the backend as it was created as required and then ran the deployment - guess what the Masterpage was reset again!!!!

This has gone beyond a joke and I would recommend anyone thinking about going down the customization and deployment routes to seriously consider the time and resources required.

We will be raising this issue with our Gold Supplier and get them to raise a ticket with MS.

Wednesday, 7 May 2008

Create a Custom Site Definition

I just came across this article by Eric Shupps on how to create a custom site definition. It looks as though it may help in the deployment issues where custom masterpages are not carried across to the WFE.

Tuesday, 2 October 2007

Ajax Calendar Extender and Master Pages

I thought I might as well share this, if it's not common knowledge.

If you have a MasterPage.page and you want to include styles based on the child page you can add the script into the page but this will result in an issue with viewing the designer in Visual Studio 2005. I eventually found a solution to add the stylesheet to the header in code:


protected void Page_Load(object sender, EventArgs e)
{
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "~/default.css";
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Header.Controls.Add(cssLink);

}

On the calendar extender I was puzzled to see that when a user selected the date the control remained visible. To get round this use an image and the PopUpControlID of the extender and the control will disappear. By setting the text boxes to Enabled=false the user only has the option of using the image to get the calendar to show. I suppose you could use the TextChanged event but this would not stop user error.