Change the URL of a list in SharePoint 2007

by Heathesh 28. January 2010 01:16

In order to do this, you will need remote desktop access (or similar) to the relevant SharePoint server. You will also need an administrator account, with which you will need to log onto the server with.

So to begin, the first thing you need to do is to create a little console app that will accomplish the required task. Next, you need to copy the Microsoft.SharePoint dll from the server locally, and add a reference to your project to it. You should find the DLL on your SharePoint server here:

    C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

Next, add the relevant using to your code:

    using Microsoft.SharePoint;

Now you can simply add the following code to your Main method:

    static void Main(string[] args)
    {
        try
        {
            //we need the privileges to execute the moveto command
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                //connect to the site collection
                using (SPSite mySite = new SPSite("http://server"))
                {
                    //open the relevant site
                    using (SPWeb myWeb = mySite.OpenWeb("TestSite"))
                    {
                        //loop through the lists
                        foreach (SPList list in myWeb.Lists)
                        {
                            //when we find the correct list, change the name
                            if (list.RootFolder.Name == "TestList")
                            {
                                //move the root folder
                                list.RootFolder.MoveTo(list.RootFolder.Url.Replace("TestList", "TestList_New"));
                            }
                        }
                    }
                }
            });

            Console.WriteLine("Done");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: {0}", ex);
        }

        Console.ReadLine();
    }


And lastly, compile the application, copy it over to your SharePoint server, and run it...

Tags: , , , , , , ,

Development | .Net | SharePoint

Comments are closed



Powered by BlogEngine.NET 1.5.0.7 (with enhancements by Heathesh)
Theme by Mads Kristensen (with tweeks by Heathesh)

Certifications

Microsoft Certified Professional

Microsoft Certified Technology Specialist

Answer Questions

 

Tag cloud

Calendar

<<  September 2014  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

View posts in large calendar

http://heathesh.com