Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, September 22, 2014 2:57 PM
Hi Everyone
I want to get all the images name inside the folder which is present in list.
site>list>folder>files
I want to achieve this using csom code.
please help me i am able to get the list but not folder names and files.
Thanks in advance.
All replies (3)
Tuesday, September 23, 2014 8:59 AM âś…Answered
Hi,
The code below returns all the names of files in a library without folders for your reference:
public static void getAllFilesInAllFolders()
{
ClientContext clientContext = new ClientContext("http://sp");
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Lib01");
clientContext.Load(spList);
clientContext.ExecuteQuery();
if (spList != null && spList.ItemCount > 0)
{
Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =
@"<View Scope='RecursiveAll'>
<Query>
<Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where>
</Query>
<ViewFields><FieldRef Name='FileLeafRef' /></ViewFields>
</View>";
ListItemCollection listItems = spList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach (var item in listItems)
{
Console.WriteLine(item.FieldValues["FileLeafRef"]);
}
}
}
You can also use CAML Designer to build the query statement if there are other requirements:
http://karinebosch.wordpress.com/2012/02/03/caml-and-the-client-object-model/
Best regards,
Patrick
Patrick Liang
TechNet Community Support
Monday, September 22, 2014 3:08 PM
Hi,
This is a good link with example.
Pradip T. MCTS(SharePoint 2010/Web)|MCPD(Web Development) https://www.mcpvirtualbusinesscard.com/VBCServer/paddytakate/profile
Monday, September 22, 2014 6:32 PM
Other way to get this information OTB is
>> Create a standard view for the image library and Select Folder Section and then select "Show all items without folders"
Export the Library to excel. You'll get the names along with other information too.
hope this helps.
Bistesh