By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,560 Members | 2,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,560 IT Pros & Developers. It's quick & easy.

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

P: 3
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.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.SharePoint;
  7. namespace folderprog
  8. {
  9.     public class folder:SPItemEventReceiver 
  10.     {
  11.        SPSite site;
  12.        SPWeb web;
  14.         public override void  ItemAdded(SPItemEventProperties properties)
  15.         {
  16.             //base.ItemAdding(properties);
  17.             site = new SPSite("http://a2ms04866:6000/presales");
  18.             web = site.OpenWeb();
  19.             SPListItem mainitem = properties.ListItem;
  20.             string fname=Convert.ToString (mainitem ["Name"]);
  21.             SPList list = web.Lists["Request For Proposal"];
  22.             if (list.EnableFolderCreation != true)
  23.             {
  24.                 list.EnableFolderCreation = true;
  25.                 list.Update();
  26.             }
  27.             string url = "http://a2ms04866:6000/presales/Request%20For%20Proposal";
  29.              list.Folders.Add(url , SPFileSystemObjectType.Folder, fname);
  31.             list.Update();
  32.         }
  33.     }
  34. }

can somebosy help me on this ??

Mar 31 '09 #1
Share this Question
Share on Google+
1 Reply

Expert 2.5K+
P: 3,525
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.Directory
Within that is a method for creating directories, as well as many other useful functions
Mar 31 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.