Wednesday, August 3, 2011

Update folder name of List or Library programmatically in sharepoint 2010

Sharepoint Document Library
==========================
if (oWeb.Lists.TryGetList("Working Documents") != null)
{
SPList listWorkingDocs = oWeb.Lists["Working Documents"];
folderUrl = oWeb.Url + "/" + listWorkingDocs.Title + "/" + listPreviousTitle;
SPFolder folder = oWeb.GetFolder(folderUrl); //listWorkingDocs.RootFolder.SubFolders[listPreviousTitle];
if (folder.Exists)
{
SPListItem item = folder.Item;
item["BaseName"] = "newfoldername";
item.SystemUpdate(false);
}

}

Sharepoint List
===================SPList listTasks = oWeb.Lists["Tasks"];
folderUrl = oWeb.Url + "/Lists/" + listTasks.Title + "/" + foldername;

SPFolder folder = oWeb.GetFolder(folderUrl);
if (folder.Exists)
{
  SPListItem item = folder.Item;
  item["FileLeafRef"] = "newfoldername";
 item.SystemUpdate(false);
}

No comments:

Post a Comment

Followers

Blog Archive