We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

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,
            SPFileSystemObjectType.Folder);
                   
        /* set the folder name and update */
        folderItem["Title"] = "New_Folder_Name";
        folderItem.Update();
 
        oSPWeb.AllowUnsafeUpdates = false;
    }
 
    oSPsite.AllowUnsafeUpdates = false;
}


Related Tags:

SharePoint

Author: Kaushik Mohanty

top

Related Pages

  • SharePoint Custom Development
  • SharePoint Custom Projects

SharePoint

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login