In this article, I am going to create folder inside a document library using the SharePoint object model or in other words using .Net code.
I do have a document library called “My Documents”. I am going to add folder this library. Currently the documents in library are as below.
- User will enter name of the folder to be created in the textbox.
- Window form contains one textbox and one button.
- Add the reference of Microsoft.SharePoint.dll in the window application.
Form1 : Form
void Form1_Load(object sender, EventArgs e)
void btnFolderCreate_Click(object sender, EventArgs e)
SPSite _MySite = new
SPWeb _MyWeb = _MySite.OpenWeb();
SPDocumentLibrary _MyDocLibrary = (SPDocumentLibrary) _MyWeb.Lists["My Documents"];
SPFolderCollection _MyFolders = _MyWeb.Folders;
_MyFolders.Add(“http://adfsaccount:2222/My%20Documents/” + txtUpload.Text + “/”);
- SPSite is returning the site collection. URL of the site collection is being passed to the constructor.
- SPWeb is returning the top level site.
- SPDocumentLibrary is returning document library as a list. A point here to be noted is that document library is basically a list in SharePoint. So I am returning document library as a list and typecasting that in SPDocumentLibrary
- SPFolderCollection is returning the entire folder in the web.
- I am adding the folder in the folder list.
- Updating the document library.
In this article, I have shown how to create a folder in SharePoint document library. Thanks for reading.