0

How to get the id of the folder in modern experience Example:https://xyz.sharepoint.com/sites/sample/Lists/Special%20characters%20list/AllItems.aspx?id=%2Fsites%2Fsample%2FLists%2FSpecial%20characters%20list%2F%2525

I want this id using Csom

1 Answer 1

1

PowerShell code:

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

$SiteURL="https://xyz.sharepoint.com/sites/sample"
$UserName="[email protected]"
$Password = "abc"
$listName ="Special characters list"

$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$SecurePassword)

#Bind to Site Collection
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$ctx.Credentials = $Creds

$list = $ctx.Web.Lists.GetByTitle($listName)
$q = New-Object Microsoft.SharePoint.Client.CamlQuery
$q.ViewXml = '<View Scope="RecursiveAll"><Query><Where><Eq><FieldRef Name="FSObjType" /><Value Type="Integer">1</Value></Eq></Where></Query></View>'
$items = $list.GetItems($q)
$ctx.Load($items)
$ctx.ExecuteQuery()
foreach($item in $items)
{
  Write-Host -ForegroundColor green "id: " $item["FileRef"]
}

C# code:

string targetSiteURL = @"https://xyz.sharepoint.com/sites/sample";

var login = "[email protected]";
var password = "abc";

var listName = "Special characters list";
var securePassword = new SecureString();
foreach (char c in password)
{
    securePassword.AppendChar(c);
}
SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

ClientContext ctx = new ClientContext(targetSiteURL);
ctx.Credentials = onlineCredentials;

var list = ctx.Web.Lists.GetByTitle(listName);
var q = new CamlQuery();
q.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>1</Value></Eq></Where></Query></View>";
var items = list.GetItems(q);
ctx.Load(items);
ctx.ExecuteQuery();
foreach(var item in items)
{
    Console.WriteLine("id: "+ item["FileRef"]);
}
Console.ReadLine();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.