Tuesday, January 25, 2011

Metadata Services: “The required feature is not enabled for this column type.”

If you are trying to enable metadata and you receive the following error:


“The required feature is not enabled for this column type.”




you should enable the following features via console:

Stsadm -o activatefeature -id 7201d6a4-a5d3-49a1-8c19-19c4bac6e668 -url http://tuwebapp/ –force


Stsadm -o activatefeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -url http://tuwebapp/ –force

This should solve your problems.

Regards,

Tuesday, January 11, 2011

Persisting state in Sharepoint timer job definitions


Using class member variables will not work if you want to persist state between invocations. This seems to be due to the way sharepoint manages timer jobs. A solution is to use the Properties *property* which is exposed to all SPJobDefinition subtypes. This is a hashtable which accepts a key value pair. Usage:

public class SampleTimerJob : SPJobDefinition
{
    public SampleTimerJob(string jobName, SPWebApplication webApplication, string url, string email)
        : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
    {
        ContainerSite = url;
        Email = email;

        this.Title = "sample timer";
    }

    public string ContainerSite
    {
        get { return Properties["site"].ToString(); }
        set { Properties["site"] = value; }
    }

    public string Email
    {
        get { return Properties["email"].ToString(); }
        set { Properties["email"] = value; }
    }

    public override void Execute(Guid targetInstanceId)
    {
        SPSite site = new SPSite(ContainerSite);

        using (SPWeb web = site.OpenWeb())
        {

            SPUtility.SendEmail(web, false, false, Email,
                                "title",
                                "content");
        }
    }
}

Friday, January 7, 2011

Using a Config File for Windows SharePoint Services Timer Jobs

One of the biggest problems I've had with timer jobs is that you cannot access the membership provider or role providers with them because they do not have a configuration value.  Then if you want to read from a configuration file, you have to point it to one of the web.configs of the site.
 
Not any more.  I was looking around for a way to add an app.config to the timer service and stumbled upon Jason Huh's blog post about using the Microsoft Enterprise Library with Timer Jobs.  I figured I would be able to use the same configuration for my projects.
 
All you need to do is create a config file for OWSTimer.  You can do this one of two ways, you can deploy this using a solution or you can do it manually. 
 
To do it manually, navigate to the hive (Program Files\Common Files\Microsoft Shared\web server extensions\12) and then open up the BIN folder.  Now create a new file named OwsTimer.exe.config.  In this file, you can place your config settings, this works just like an app.config or a web.config file that you would add in visual studio.
 
I've placed an example config file, but the Membership Provider and Role Provider nodes are not filled all of the way out, you can replace this with your own information or just remove the membership and role manager nodes completely.
 
xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="ConnString" connectionString="ConnectionStringGoesHere" />
connectionStrings>
<system.web>
<membership defaultProvider="MembershipProvider">
<providers>
<add name="MembershipProvider" />
providers>
membership>
<roleManager enabled="true" defaultProvider="RoleProvider">
<providers>
<add name="RoleProvider" />
providers>
roleManager>
system.web>
<appSettings>
<add key="SiteUrl" value="http://sharepointsite"/>
<add key="ProviderPrefix" value="RoleProvider"/>
appSettings>
configuration>
 
Using this, you will be able to finally use a configuration file with your timer services without having to hard code the site that you are going to read the config settings from.

Tuesday, January 4, 2011

Talking about owstimer.exe.config

When a new timer job is created for Sharepoint, it has to be programatically installed in a SPWebApplication.JobDefinitions of type SPJobDefinitionCollection. If the timer job have to receive some settings during run time, one option would be to use the .Net application configuration feature.
First you might think to copy the configuration section from the app.config of the dll where the timer job resides into the web.config of the web application where the timer job is registered. The first catch: the timer job is loaded by the timer service, which is the 'Windows SharePoint Services Timer' Windows service on the web front end servers and runs the "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\OWSTIMER.EXE" executable, so we have to configure this service.
This can be done by creating the OWSTIMER.EXE.config file near the exe file, and put there the timer job configuration section.
Don't forget to restart the timer service :-).