Progammatically Adding Folders to a SharePoint List

This took me longer than it should have to get working as the things I tried first compiled but did nothing:

 myList.Folders.Add("DoesNotWork", SPFileSystemObjectType.Folder);

The way I got it to work in the end was like this: 

            SPList myList = myWeb.Lists["My List"];
            SPListItem newFolder = myList.Items.Add(myList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, null);
            if (newFolder != null)
            {
                newFolder["Name"] = "Name of Folder";
                newFolder.Update();
            }

Hope this helps somebody :-)

Published Thursday, August 30, 2007 12:19 PM by adamhems

Comments

# MSDN Blog Postings » Progammatically Adding Folders to a SharePoint List @ Thursday, August 30, 2007 3:37 PM

PingBack from http://msdnrss.thecoderblogs.com/2007/08/30/progammatically-adding-folders-to-a-sharepoint-list/

MSDN Blog Postings » Progammatically Adding Folders to a SharePoint List

Anonymous comments are disabled
 
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker