How to rename folder in document library in sharepoint using Csom Script?
lp
How to rename folder in document library in sharepoint using Csom Script?
lp
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Cr BhargaviPosted Aug 15, 2023, 3:28 AM
Nidhi RajPosted Aug 14, 2023, 4:50 PM
Can you please help me with renaming of folder in document library in SharePoint using Csom as there is folder inside folder in that particular document library.In that case how can one able to rename folder? Kindly help me with this
Tahir AnsariPosted Aug 8, 2023, 4:06 PM
using System;
using Microsoft.SharePoint.Client;
namespace RenameFolderCSOM
{
class Program
{
static void Main(string[] args)
{
string siteUrl = "https://yoursharepointsiteurl";
string username = "yourusername";
string password = "yourpassword";
ClientContext context = new ClientContext(siteUrl);
context.Credentials = new SharePointOnlineCredentials(username, ConvertToSecureString(password));
Web web = context.Web;
List list = web.Lists.GetByTitle("Your Document Library");
context.Load(list);
Folder folder = list.RootFolder.Folders.GetByUrl("Your Folder URL");
context.Load(folder);
folder.MoveTo("New Folder Name");
context.ExecuteQuery();
Console.WriteLine("Folder renamed successfully.");
}
private static System.Security.SecureString ConvertToSecureString(string password)
{
System.Security.SecureString securePassword = new System.Security.SecureString();
foreach (char c in password.ToCharArray())
{
securePassword.AppendChar(c);
}
return securePassword;
}
}
}