SIGN UP MEMBER LOGIN:    
ARTICLE

Programmatically create folder in SharePoint List

Posted by Vijai Anand Articles | SharePoint August 12, 2011
In this article we will be seeing how to create folder in SharePoint list using SharePoint Object Model.
Reader Level:

In this article we will be seeing how to create folder in SharePoint list using SharePoint Object Model.

Steps Involved:

  1. Open Visual Studio 2010.
  2. Go to File => New => Project.
  3. Select Console Application template from the installed templates.
  4. Enter the Name and click on Ok.
  5. Add the following reference.

    • Microsoft.SharePoint.dll
     
  6. Add the following Namespace.

    • Using Microsoft.SharePoint;
     
  7. Replace Program.cs with the following code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;

    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (SPSite site = new SPSite("http://serverName:25374/sites/Team/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList list = web.Lists.TryGetList("Custom");
                        SPListItem folderColl = list.Items.Add(list.RootFolder.ServerRelativeUrl,SPFileSystemObjectType.Folder);
                        folderColl["Title"] ="New Folder";
                        folderColl.Update();
                        list.Update();                   
                    }
                }
            }
        }
    }


    8. Build the solution.
    9. Hit F5.
    10. Go to the SharePoint list and you could be able to see the new folder that we have created.

    Sharepoint

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor