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...