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, 26 February 2009

Adding Metadata to a MOSS 2007 Publishing Portal

I found a way of adding MetaData to each page within a public facing website. There are still discussions on whether it is of any value, as some search engines don't always read it, to change the description and keywords.

In the Content Type(s) that the pages use add three fields - one for page title that will appear in the browser and will not affect the title used for the .aspx and in menus, one for the description as for some reason the description added when the page is created is not used (though I don't know it is crawled and returned in search results) and keywords.

I didn't add these fields to the page layout as there are lots of pages for our Marketing department, who own the content, to redo.

I'll post up the rest of the code tomorrow as I don't have the code at home.

Friday, 13 February 2009

Create custom 404 in MOSS 2007

http://support.microsoft.com/kb/941329/en-us

We had an issue where our new site had the same Url as the old one and Google search results were returning the old one which was no longer visible (Url pointing to new IP address) the above link is to the Microsoft Knowledge Base article for a solution. It worked for us.

Tuesday, 10 February 2009

Entity Framework

Finally got the EF to install!! It appears that VS2008 did not have SP1 and non of this was picked up on the updates. Once installed the DataModeller appered

Monday, 9 February 2009

Entity Framework Tests

Just a quick one – guess I was being an idiot (no change there then). I was creating a couple of tests for my entity model and got an error

"The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."

A little bit of searching revealed that I needed an app.config for the test project with the connection settings for the model – makes sense but was confusing at first.

Entity Framework

Had some problems, and still do, installing the Entity Framework on my home laptop. At one point after un-installing 3.5 SP1 and the updates VS2008 decided that it would also delete all my templates.