SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know this might be a silly question but here goes. I intend to create a list using C# code. I do know the code but the question is, where exactly should I write the code in Visual studio. I mean which template to use (webpart, visual webpart) and do I need to add some references.

share|improve this question

Check this post . it will give you some ideas.

To answer your question, You can write the code wherever you want and it depends on the scenario. I can use a Visual WebPart to create a new list.

I can also develop a event handler/feature to create a list programatically. Above link uses List Definitions.

share|improve this answer
'It depends' should be part of almost every SharePoint answer :-) – Bart Jun 6 '11 at 8:42

Shoban said the critical phrase in his answer.

It Depends

It really does depend on your situation. Normally I have lists created upon site creation, so I'll do this via CAML code and have it as part of a feature.

But you may need to create lists as part of a business process, within a workflow, or within an event handler.

Shoban's link refers to list definitions. This isn't necessary if your situation requires you to, for example, just create a Links list. You can just fire in the appropriate TemplateType in this case.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.