Populate all the folders in a document library - sharepoint

I want to populate all the folders in document library to a drop down. I was thinking of using spquery for it but not sure how to retrieve all the folders with it.

You shoudl use the root folder of the lib and from that folder iterate through its Folders collection. Note that you need to set web.Lists.IncludeRootFolder to true to get access to the root folder.
But something I don't understand - folders have a tree-like structure, how do you intend to put them into a flat ddl?

Related

Excel Power query: search one folder deep

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

Automatically create Subfolders on SharePoint Document Library

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.

Accessing all the files from a folder

I'm trying to access all the files from a certain folder so that I can get their path and put it into an array. Once I get this array, I'd like to use it in a react file and display its contents on a page. I had a general idea of looping through the folder but couldn't find a solution to my problem. Is there a way to do this, directly or maybe through a third-party package?

sharepoint workflow to move files of a content type to new folder (after creating it if needed)

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

extendscript, get folder name

I have been learning and using Extendscript with After Effects CS6 (normally use maxscript and python) to create a dockable UI for After Effects. I have managed to do this, but need to restructure the code to search within folders in a root folder to grab the .jsx files that form the nodes on the treeview I have created.
currently, all the .jsx files are in one root folder, but due to a restructuring of the folder system, we now have a folder that houses each script
I need to be able to return/collect the names of folders within the root folder into an array that I can loop over in the later part of the script.
So far I have code that will return the path to the folders inside the root folder, but this is not what I need and I do not want to have to split the strings into constituent parts just to get the last part of the path.
The root folder in the image below is "c:\AFX\theRoot\" with folders inside named script1, script2, script3 script4
I was going to post an image of the folder structure, but I am not allowed due to a requirement to have a specific rating.
If you already have strings. Operating on them is probably the easiest way to get the folder name. Instead of splitting you could also use a regex like this:
var name = yourString.match(/([^\/]*)\/*$/)[1]
Credit for the regex goes to this thread
If you have some reason not to do it this way, there is the folder object in ExtendScript. You can create a new folder from a string like this:
var folder = new Folder("/your/folders/name");
And get the name like this:
var name = folder.name
Hope this helps.

Resources