Showing posts with label Object module. Show all posts
Showing posts with label Object module. Show all posts

Tuesday, February 23, 2010

Sharepoint - Rename site column back to "Title"

I guess some of you bumped into a problem while changing the famous site column "Title" into something else and asking yourself OK... i made an error and now i need to fix it
but writing Title back and clicking OK pops up an error that saying that the column "Title" can't be used cause it saved value.

Well there's a simple explanation to this problem and as you can see the "Title" is a value that the Sharepoint environment keeps to itself

So you must be asking yourself, so OK now what? i need to be stuck with this error i made?
the answer is no...
not really.

As you know there are basically three, lets call it, layers to handle with Sharepoint environment stuff
  • SQL
  • IIS (Server Side)
  • Sharepoint Code (AKA Object Module)
First two wont really help you out in this case and you need to approach it the programmer way (but don't worry there's nothing spooky about it)

All you're need to do is:
  • Open your latest version of visual studio and create console application, based on vitual basic .Net 3+ framework.
  •  Add the "Microsoft.SharePoint.dll" to your references (it can be found at your moss installation directory, or most of the time at "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\ISAPI"
  • Add the next code to your application:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace RenameField
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Usage: RenameField ");
                return;
            }

            SPSite site = new SPSite(args[0]);
            SPField f = site.RootWeb.Fields[args[1]];
            f.Title = args[2];
            f.Update();
        }
    }
}
  • Build and try it on a side server. (Just keep in mind that you need to apply the change after the rename from the Site collection administration page or else the change wont be applied over your site collection.