Was trying to create Folder programatically in a Doc Library(SharePoint Site)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jags
    New Member
    • Mar 2009
    • 3

    Was trying to create Folder programatically in a Doc Library(SharePoint Site)

    HI All

    I was trying to create Document librray programatically in a Sharepoint Site and is not working for me.I was trying to implement this as an Event Handler.
    The aim of the code is to create a Folder with the same name as in folder which has been added.For eg if i am creating a folder titled A in a Doc library called A1 then I shud have a folder names A in a document library called as 'Request for Proposals' (this is predifened)
    below is the piece of code.


    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    
    namespace folderprog
    {
        public class folder:SPItemEventReceiver 
        {
           SPSite site;
           SPWeb web;
           
            public override void  ItemAdded(SPItemEventProperties properties)
            {
                //base.ItemAdding(properties);
                site = new SPSite("http://a2ms04866:6000/presales");
                web = site.OpenWeb();
                SPListItem mainitem = properties.ListItem;
                string fname=Convert.ToString (mainitem ["Name"]);
                SPList list = web.Lists["Request For Proposal"];
                if (list.EnableFolderCreation != true)
                {
                    list.EnableFolderCreation = true;
                    list.Update();
                }
                string url = "http://a2ms04866:6000/presales/Request%20For%20Proposal";
                
                 list.Folders.Add(url , SPFileSystemObjectType.Folder, fname);
           
                list.Update();
            }
        }
    }

    can somebosy help me on this ??

    Jags
    Last edited by tlhintoq; Mar 31 '09, 02:20 PM. Reason: [CODE] tags added. Vast white space removed
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that

    wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on

    it. More on tags. They're cool. Check'em out.

    You want to read up on System.IO.Direc tory
    Within that is a method for creating directories, as well as many other useful functions

    Comment

    Working...