Today I had a requirement to add folders programmatically to the default ‘Site Collection Images’ document library. Its quite simple and can easily be achieved with few lines of code. Here is a method of how to do that:
//Remember Document library is also a list in SharePoint String url = site.Lists["Site Collection Images"].RootFolder.ServerRelativeUrl.ToString(); SPFolderCollection folders = site.GetFolder(url).SubFolders; //Create new folder folders.Add("Newfolder");
You can use the same code to create folders/subfolders in any custom document library as well.
Thanks for the post, i need to know how to add folder to “Site collection images” from specific conetnt type associated already to the Library, suppose we add special kind of conetnt type “Galery Folder” .. so how to add new folder to the Images Library.
Bingo !!! i was loking 4 exact thing.
Thank you, sorry to ask, but would i add code to have this function automated.. Basically I was to insure that folders A B C D E are always created in this specific portal, when new children portals are created.
couldn’t you just do:
SPFolderCollection collection = site.Lists[“Site Collection Images”].RootFolder.SubFolders;
Juan, seems like it should work but I haven’t tried it. I will give it a try and will update the post accordingly.
Thanks for visiting my blog.
I tried your code, it works great. However, I don’t see the created folder in explorer view. How come?
Where do I write this code? I mean in a web part or ?
Shobha, you can add this code anywhere as far as you have access to “site” object.
I used it on Feature Activation.
Thanks Praveen, I have tried it works fine.
Is it possible to create a document library within another document library? I would like to attached different automatic workflows to different document libraries within a main document library.
Is this possible thur GUI or programmatically?
SharePoint doesn’t allow to create document library within another document library. However you can associate multiple content types to a document library and each content type can have a unique workflow attached to it.
You can also create a View for each content type which will give you the similar feel as having document library within another document library.
Hope this helps!
Is there a tool to build more than one wsp files as setup.exe. We need to install share point solution include web parts, lists, custom content types etc. We need build installer as exe file to do all in one short. Plese suggest me any tools available in achieving this.
I am not aware about the tool to build the installer.
However I would create a batch files which deploys multiple WSP’s. I think it much easier approach to achieve the same objective.
Any thoughts on how I would go about creating a folder as part of a workflow (using SPD)? – Ideally the folder would be on a Document Library on a SubSite.
Thanks in advance!
I’m using macros in word and trying to create a folder in sharepoint if it’s not found. The macro I currently have uses bookmarks in the document and works in my local desktop but will not work in sharepoint (Dir, MkDir).
I understand that they are different programs and some vb languages are different. Most macros reference the address where to look for something. In your example I don’t see the address referenced. New to Sharepoint so just now learning to navigate through it
Would be greatful for any help.
Check this helpful link….
Its also having with wonderful explanation on Create a Document in SharePoint and add folder in SharePoint Document using C#.
I apologize if this is a reduntant question. I have a List, when the list is created I want it to create a folder in a document library using a couple of the column names in the original list. I am using Designer 2007. Any help is appreciated.
How Can i add folder in document library using document object model
Many thanks to people who willingly share what it takes to make life online a little easier. You have no idea how much this is appreciated.
Thanks for the post.It helped me very much.
I am a complete noob, so here is my stupid question: where do i put this code? does is go in a data connection? or is it a file? what is the extension? how do i fire it off?