Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SharePoint > SharePoint Development
SharePoint Development Programming and development for SharePoint Portal Server and Windows SharePoint Services
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SharePoint Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 29th, 2010, 07:58 AM
Authorized User
Join Date: Jan 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elizas
Default Programmatically creating Folders within SharePoint List

Hi all,
I would like to share a tip.I am sure it would be beneficial.
Folders help group related items within a list. The code snippet provided below (in C#.Net) explains the approach of creating a folder within a specific list.

using (SPSite oSPsite = new SPSite("http://website_url"))
oSPsite.AllowUnsafeUpdates = true;

using (SPWeb oSPWeb = oSPsite.OpenWeb())
oSPWeb.AllowUnsafeUpdates = true;

/* Path within the list where the new folder gets created
Leave it empty if it needs to be created under root */
String nodeDepthPath = @"/MyRootFolder";

/* get the list instance by name */
SPList list = oSPWeb.Lists["List_Name"];

/* create a folder under the path specified */
SPListItem folderItem = list.Items.Add(
list.RootFolder.ServerRelativeUrl + nodeDepthPath,

/* set the folder name and update */
folderItem["Title"] = "New_Folder_Name";

oSPWeb.AllowUnsafeUpdates = false;

oSPsite.AllowUnsafeUpdates = false;


Mindfire: India's Only Company to be both Apple Premier & Microsoft Gold certified.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with creating folders kuznickic VBScript 0 August 13th, 2007 03:26 PM
Creating folders on network share JonniP Access VBA 1 January 3rd, 2007 03:51 PM
creating a list of folders hillbilly geek PHP How-To 1 December 28th, 2005 09:32 AM
Creating report programmatically liliarum BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 6th, 2004 09:34 AM
Creating Tables Programmatically stu9820 ASP.NET 1.0 and 1.1 Basics 10 October 22nd, 2003 04:25 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.