How to create Document Library with Custom Fields
When you create Document Library on Sharepoint site, it is sometimes necessary to assign additional custom Fields or columns to a document.Creating columns is simple procedure in a case of using the Sharepoint UI. But developers in a certain scenarios have to create the solution as a WSP package.
In this tutorial I will show how to create Document Library in Visual Studio with additional Custom Fields.
You should follow these steps:
- Create a Blank Site Definition
- Create Document Library
- Add Custom Field to Document Library
- Deploy Site definition with Document Library
- Create site from Site definition
- Test Custom Field in Document Library
1) Create a Blank Site Definition
- run Visual Studio with VSeWSS- in Menu choose creating new project: File -> New -> Project
- in tree list navigate to group named Sharepoint and choose creating Blank Site Definition
- type the Name and Location of project and click OK

2) Create Document Library
- right click Project in Solution Explorer- in context menu choose: Add -> New Item
- in tree list navigate to Sharepoint group and choose List Definition
- click OK

- as a Base of List Definition choose: Document Library and check Create an instance of this list
- click OK
- now we have prepared empty Site definition project with Document Library list

3) Add Custom Field to Document Library
- locate and open schema.xml of created list- remove node ContentTypeRef with attribute ID="0x0101" from ContentTypes node
- insert following ContentType node to ContentTypes node:
DocumentLibraryForm
DocumentLibraryForm
DocumentLibraryForm
- under the Fields node insert following Custom Field:
- now your List definition schema should looke like this:

4) Deploy Site definition with Document Library
- right click Project in Solution Explorer and in context menu choose Properties- on Debug tab set Start action to Start browser with URL and define url address of sharepoint cetral administration site, in my case: http://localhost:29040/
- save Project properties
- right click project again and choose: Deploy
- in status bar you will see: Deploy succeeded
- now we have deployed Site definition with Document Library list expanded with Custom Fields
5) Create site from Site definition
- go to your central administration and choose tab Application Management- in group Sharepoint Site Management click Create site collection
- fill title of site and optionally description
- click on the development tab and choose our Site definition
- fill desired administrator username and click OK

- after a while you will see message: Top-Level Site Successfully Created
- now open the new created site link
6) Test Custom Field in Document Library
- open link View All Site Content and check that Document Library was created
- when you open created list you should update current view by choosing View: All Documents -> Modify this View
- on Columns group check Custom Field checkbox and click OK to save changes

- now when you upload file or create Document within Microsoft Office Word, at saving sharepoint site will ask for Custom Field value

- on next picture you see one item created by Word and one item uploaded both with Custom Field value assigned

Document Library with additional Custom Field was successfuly deployed and created.
Back to Top