PHP-SharePoint-Lists-API icon indicating copy to clipboard operation
PHP-SharePoint-Lists-API copied to clipboard

Get folder contents inside the list

Open tejaskesaria opened this issue 9 years ago • 11 comments

Hi,

Thanks for the great API. My sharepoint site has folders in which several documents are present. Normally when I run these: $data = $sp->read('Documents'); On var dump I get array of all list, I have a folder inside the list and need to get the list inside the folder.

I tried:

$listName = 'Documents';
$folderName = 'Staff';
$d1 = $sp->read($listName,NULL,NULL,NULL,NULL,"<Folder>" .$listName . "%2F" . $folderName."</Folder>");
var_dump($d1);

But it doesn't return the list inside the folder("Staff").

Normally by doing this: $data = $sp->read('Documents',1); $max = sizeof($data); for($i = 0; $i < $max;$i++){ $filename = $data[$i];echo "<div>"; $str = $filename["linkfilename"]; preg_match('"([^\\"]+)"', $str, $result); echo $result[0]; echo "</div>"; }

Gives me the name of folder.

@thybag can you help on this.

tejaskesaria avatar Jan 11 '17 08:01 tejaskesaria

Hi, Did you get any luck with this, I am trying to achieve the same. I have folders in list and files in folders that I am trying to download or at least get links to them if not able to download. Thanks

khawaib avatar Feb 07 '17 20:02 khawaib

Have you tried this?

$sp->read($listName, NULL, NULL, NULL, NULL, '<ViewAttributes Scope="RecursiveAll"/>')

This lets me list all files in the folders

sc3499 avatar May 26 '17 10:05 sc3499

Hi,

I used this to get list of files. $files = $sp->readFromFolder('insight', $d['linkfilename'], true);

khawaib avatar May 26 '17 10:05 khawaib

Hi,

I used this to get list of files. $files = $sp->readFromFolder('insight', $d['linkfilename'], true);

No way I can do it work :( I have a document set in a folder and I cannot access it this way. I get the same response with or without the folder: $files = $sp->readFromFolder($listName, 'ES0234150000749050LW', false, 1); no files or URLs in the response: array(1) { [0]=> array(26) { ["linkfilename"]=> string(20) "ES0234150000749050LW" ["estadoexpediente"]=> string(7) "Cerrado" ["fechaexpediente"]=> string(19) "2017-04-24 00:00:00" ["edit"]=> string(1) "0" ["itemchildcount"]=> string(8) "62261;#4" ["comercializadora"]=> string(25) "17;#GAS NATURAL SERVICIOS" ["comercializadora_x003a_codigo"]=> string(8) "17;#0033" ["modified"]=> string(19) "2017-05-29 17:07:47" ["migracion_lote"]=> string(16) "6.00000000000000" ["doc_carta"]=> string(2) "Si" ["doc_certificado"]=> string(2) "Si" ["doc_oca"]=> string(2) "No" ["_moderationstatus"]=> string(1) "0" ["_level"]=> string(1) "1" ["uniqueid"]=> string(45) "62261;#{0F5D8133-F0FD-4939-B65B-DAB4911AB2B8}" ["fsobjtype"]=> string(8) "62261;#1" ["created_x0020_date"]=> string(26) "62261;#2017-04-27 16:59:44" ["progid"]=> string(29) "62261;#Sharepoint.DocumentSet" ["fileleafref"]=> string(27) "62261;#ES0234150000749050LW" ["permmask"]=> string(12) "0xb008431061" ["html_x0020_file_x0020_type"]=> string(22) "Sharepoint.DocumentSet" ["fileref"]=> string(62) "62261;#teams/Incidencias/ListaExpedientes/ES0234150000749050LW" ["editor"]=> string(26) "15;#Usuario de Incidencias" ["last_x0020_modified"]=> string(26) "62261;#2017-06-05 12:51:57" ["id"]=> string(5) "62261" ["owshiddenversion"]=> string(2) "10" } }

The URL for one of the files is /teams/Incidencias/ListaExpedientes/ES0234150000749050LW/2017021000000006204_es0234150000749050lw_13026696.pdf but where is it??

Any help about how to get the files URLs into this folder? I am really desperate!!!

Thx so so much If anyone helps me I will give you my whole life's support :-)))

ccarlosm avatar Apr 06 '19 09:04 ccarlosm

Hi, I used this to get list of files. $files = $sp->readFromFolder('insight', $d['linkfilename'], true);

No way I can do it work :( I have a document set in a folder and I cannot access it this way. I get the same response with or without the folder: $files = $sp->readFromFolder($listName, 'ES0234150000749050LW', false, 1); no files or URLs in the response: array(1) { [0]=> array(26) { ["linkfilename"]=> string(20) "ES0234150000749050LW" ["estadoexpediente"]=> string(7) "Cerrado" ["fechaexpediente"]=> string(19) "2017-04-24 00:00:00" ["edit"]=> string(1) "0" ["itemchildcount"]=> string(8) "62261;#4" ["comercializadora"]=> string(25) "17;#GAS NATURAL SERVICIOS" ["comercializadora_x003a_codigo"]=> string(8) "17;#33" ["modified"]=> string(19) "2017-05-29 17:07:47" ["migracion_lote"]=> string(16) "6.00000000000000" ["doc_carta"]=> string(2) "Si" ["doc_certificado"]=> string(2) "Si" ["doc_oca"]=> string(2) "No" ["_moderationstatus"]=> string(1) "0" ["_level"]=> string(1) "1" ["uniqueid"]=> string(45) "62261;#{0F5D8133-F0FD-4939-B65B-DAB4911AB2B8}" ["fsobjtype"]=> string(8) "62261;#1" ["created_x0020_date"]=> string(26) "62261;#2017-04-27 16:59:44" ["progid"]=> string(29) "62261;#Sharepoint.DocumentSet" ["fileleafref"]=> string(27) "62261;#ES0234150000749050LW" ["permmask"]=> string(12) "0xb008431061" ["html_x0020_file_x0020_type"]=> string(22) "Sharepoint.DocumentSet" ["fileref"]=> string(62) "62261;#teams/Incidencias/ListaExpedientes/ES0234150000749050LW" ["editor"]=> string(26) "15;#Usuario de Incidencias" ["last_x0020_modified"]=> string(26) "62261;#2017-06-05 12:51:57" ["id"]=> string(5) "62261" ["owshiddenversion"]=> string(2) "10" } }

The URL for one of the files is /teams/Incidencias/ListaExpedientes/ES0234150000749050LW/2017021000000006204_es0234150000749050lw_13026696.pdf but where is it??

Any help about how to get the files URLs into this folder? I am really desperate!!!

Thx so so much If anyone helps me I will give you my whole life's support :-)))

Folder is empty it seems, I must access the document set, how may I do that? Arghhh!

Thx

ccarlosm avatar Apr 06 '19 09:04 ccarlosm

Solved, I was not taking all the elements on the list!!, they were there....Many hours of stupidity spent

Thx to anyone who read in any case

ccarlosm avatar Apr 06 '19 10:04 ccarlosm

Hi, could you explain me how to enter in a folder and read all file inside???

I hava Documente\Folder1\Folder2
With File1.txt and File2.txt

My target is to have the list of all file inside Documente\Folder1\Folder2\

I tried $listContent = $sp->read($listName,NULL,NULL); $files = $sp->readFromFolder($listName . "\" . "Folde1\Folder2\");

Thanks for your help! Pier

Pier1971 avatar Feb 20 '20 08:02 Pier1971

Hello @Pier1971 , Did you find a solution for your problem ? I have the same problem !

Jedguy avatar Feb 08 '22 16:02 Jedguy

Hi,

Yes, using the thybag library with: This is the filter used for search data in the library eg contain mouse:

$filter = "mouse";

$query = '<Where><Contains><FieldRef Name="FileLeafRef"' . "/" . '><Value Type="File">' . $filter . '<' . "/" . 'Value><' . "/" . 'Contains><' . "/" . 'Where>';

$listName = "Documents"; $baseFolderName = "Shared Documents\FolderX\Folder_Y\";

$sp = new SharePointAPI($username,$userpwd,'link to your sharepoint online/_vti_bin/Lists.asmx?WSDL','SPONLINE');

$aa = $sp->readFromFolder($listName, $foldername,FALSE,100, $query); foreach($aa as $ff) { if ((trim($ff["linkfilename"] != "<")) && (trim($ff["linkfilename"]) != "N")) { ..... your code for access to all data $n++; } }

Pier1971 avatar Feb 09 '22 11:02 Pier1971

Hi @Pier1971 thanks you for your answer,

I don't understand some things, why create a baseFolderName "Shared Documents\FolderX\Folder_Y" and after on your variable $aa a variable $foldename ?

Your foreach is to display your data or to get access on yours folder ?

Jedguy avatar Feb 09 '22 14:02 Jedguy

the for each cycle it's to access to all result data. Try to to make a var_dump and see what show or access.

Pier1971 avatar Feb 09 '22 14:02 Pier1971