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
- 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