I am trying to use Microsoft Graph to list and download files in SharePoint. I'm using direct http not any library. My problem is that I cannot list child items of subfolders found in SharePoint libraries.
I start the process by using this call to obtain a list of drive Ids:
https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives
("host" is actually different for my site)
Let's say a driveId is "ABCDEF". I then use this call to obtain a list of files within the SharePoint drive:
https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives/ABCDEF/root/children
This yields for each file a fileId and filename. If my document library has a subfolder created, I can differentiate between files and folders by looking for the item "folder". The id of the subfolder looks similar to those of files. Let's say the folder Id is "XYZ".
Now I want to obtain a list of child items for the sub folder. I use this call:
https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drive/items/XYZ/children
Unfortunately this results in http error 404 with the message "The resource could not be found". I have tried variations of this url, such as drives/XYZ/root/children but nothing works.
Could someone provide me with the correct url to obtain a list of files from within a SharePoint library
subfolder?
This is because the default drive host.sharepoint.com/drive/ is different from host.sharepoint.com/drives/ABCDEF.
XYZ is under ABCDEF rather than the default drive.
Use https://graph.microsoft.com/v1.0/sites/host.sharepoint.com/drives/ABCDEF/items/XYZ/children should resolve this issue.
Related
I'm new to power automate and have been searching on Microsoft forums and googling a flow to copy all contents of a sharepoint root folder (Documents) to a local drive and cannot find an easy straight forward answer.
All i see is how to copy files to a local drive, which after trying and failing a lot, i finally found 1 flow that helped me do it in 2 steps:
1 - When a file is created;
2 - Create file
What i intend is to backup the root documents folder monthly with all other folder and files included to a local drive with power automate.
Appreciate any help.
Il post the prints on the flow i have right now:
Created Flow
Error after running flow
What happens is that one subfolder is selected and only the files on the subfolder are copied to the local drive, not the subfolder itself, and after that it stops the flow saying no dependent actions succeeded. I was expecting the following:
1 - Select files in folder and copy to chosen path;
2 - Select subfolders with files and create the same subfolders with files on the chosen path;
First you have to list all the files you need to copy to your Drive using the sharepoint Get Files action:
Next, add an Apply to each using the first dynamic content you have on the right side, normally it's a value like showed below, then add sharepoint action Get file content using path. Select the same root directory you used in the Get Files action and in the File Path property use the dynamic content Complete Path.
Next, all you have to do is create a new file using the Google Drive action Create File still inside the Apply to each. Use the file name and in File Contents use the dynamic content File contents:
I am doing a power query in excel and im just using it to list all files in a specific directory.
I have two problems:
I cannot choose a sharepoint for the query. I may only choose folders on my hard drive. Is it possible to use a network sharepoint?
When I choose the folder i want, the query digs deep in all subfolders and list all files. However, i want it to search max 1 subfolder deep. and not 300. Is it possible?
Thanks for anyone who can help me! much appreciated
PS: If there is a vba code which lists all files one subfolder deep, this would also be a great solution
You can choose a network SharePoint folder by using the SharePoint Folder connector under Get Data. But you have to only use the root folder as your target for the URL. That will bring up a list of all files that exist within the hierarchy under that root folder. From there, use the Transform Data button (not the Combine & Transform Data button). Then you can rely upon the Folder Path column to filter for your desired actual folder.
[The Folder connector works similarly to the SharePoint Folder connector, in that it will bring up a list of all files that exist within the hierarchy under the targeted folder.]
I am not aware of it being possible to go straight to your desired folder using either the SharePoint Folders connector or the Folders connector.
filter the results of your list of there is a PATH column
I have a scenario how to transfer files from sftp server to sharepoint document library
Example: files in sftp folder are /new/folder1/id1.csv /new/folder2/id2.csv like that every day the files will be uploaded to folders. how to transfer the same structure in sharepoint document library using logic apps..
The workflow for your folder structure would be as follows:
List files in your SFTP folder "/new".
Create a "For each" loop using the output of the list action as a parameter.
To make sure you don't treat files as folders (if you can have files in /new, e.g. /new/test.txt), add a condition: the IsFolder property of the loop item = true.
Inside the loop (and the condition result True) list files again, this time in the subfolder, using the Path property of the loop item.
Create a new "For each" loop using the output of this list action as a parameter.
Optionally, add a condition: the IsFolder property of the inner loop item = false.
Get content of the SFTP file, using the Id property of the inner loop item.
Create a file on SharePoint using the folder path, file name, and file content retrieved in the previous actions as parameters. If the folder doesn't exist in SharePoint library, it should be created automatically.
This is the most simple scenario, given the folder structure provided in your question. If the folder structure is more complex (subfolders can contain both files and subfolders, which in turn can contain other files and subfolders, and so on) then you'd need to use a recursive algorithm - first the Logic App would need to list files in a single SFTP folder (provided to the Logic App in the HTTP request body), then for each listed file (not subfolder) upload its content to SharePoint, and for each listed subfolder (not file) the Logic App would need to call itself passing the subfolder path in the HTTP request body - this way all subfolders would be processed recursively and all files in them would be transferred to SharePoint.
Please note that each such a workflow is run it would transfer all files - it wouldn't check what files are new, what files have been transferred in previous Logic App runs, etc. - that would be a completely different challenge.
I have been trying to accomplish this for weeks now and end up hitting a wall.
I have a document library on SharePoint Online with the following (close enough) structure.
Clients
-> Schools
-->Client Name
--->Communications
--->Documentation
--->Projects
---->Project Name 1
---->Project Name 2
->Retail
-->Client Name
--->Communications
--->Documentation
--->Projects
---->Project Name 1
---->Project Name 2
... and so on.
Inside the "Projects" folder there is a set of folders as well.
Right now we have a Project template folder that we used to just copy/paste and rename when we had our file server, but now on SharePoint, the copy to process is way too many clicks to get it to that location.
What I am trying to accomplish is be able to create a new project folder and automatically create all the folders under it.
Appreciate the guidance on this.
I was able to figure this out.
My challenge was when creating the folder, it always wanted to create it inside the root of the document library and not the subfolder.
So I created 2 Content types for folders, one for clients and one for projects.
Used SharePoint Designer to create the workflow, but the trick here was to extract the URL from the current item, which is the folder being created, and remove the first x amount of characters from it which equals the SharePoint document library location. The remaining part of the string was the exact location where I wanted the subfolders to be created.
After that, I used that variable to create all other subfolders.
I have multiple SP document libraries for different meetings. I want to keep the libraries organized by meeting day. So each meeting would have it's own folder and all the files for that day would go in that folder.
To make it easy I wanted to make it so you can upload a file and then a SP workflow will create a folder for that meeting, if needed, and move the file.
So I created a "meeting file" content type that also gets meeting date and file type (minutes, presentation, misc, etc...)...
What I need to do next is check if a folder for that meeting date exists and create it if it does not. Then move the file over to that folder.
Any ideas how I could do this?
I could also try it without using content types but then the workflow starts automatically for every file added and then I cannot create a new folder with that workflow (because it would start a new instance of that workflow).
I was hoping to keep it reusable so I could just use one workflow for all the document libraries. I thought the workflow could find the path of the list it is being run on, and create the folders and do the other work within that list.
Any ideas are appreciated.
For creating folder via workflows:
Creating folders and sub-folders using SharePoint 2010 Designer Workflow
and for checking folder name:
Create a string workflow variable.
Now create a lookup for your folder and set the variable to the folder's title. Take a look here for some helpful information and usage guidelines when it comes to list folders.
The actions dependent of the existence of the folder have to be placed inside an if-statement
E.g. the if-statement should be like "if [variable] not equals [folder name]" if you want the actions only to be run when the folder does not exist
and here the whole tutorial that I found:
Create folders using a SPD workflow