Click here to Skip to main content
15,892,281 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi all,
I got a code to create custom sharepoint list using visual studio 2010. But where can i place these code visual studio 2010
not any where its mentioned. can somebody help me pls.i am really struggling. pls help me somebody.Here is the
code:
using (SPSite oSPsite = new SPSite("http://Web URL"))
{
    oSPsite.AllowUnsafeUpdates = true;
 
    using (SPWeb oSPWeb = oSPsite.OpenWeb())
    {
      oSPWeb.AllowUnsafeUpdates = true;
 
      /* 1. create list from custom ListTemplate present within ListTemplateGalery */
      SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
      SPListTemplate template = lstTemp["custom template name"];
      oSPWeb.Lists.Add("List Name", "Description", template);
 
 
      /* 2. create list from sharepoint list content type (e.g. Links) */
      oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links);
 
      oSPWeb.AllowUnsafeUpdates = false;
    }
 
    oSPsite.AllowUnsafeUpdates = false;
}
Posted
Updated 20-Apr-11 2:31am
v3
Comments
Toniyo Jackson 20-Apr-11 3:17am    
Pre tag added
pankajupadhyay29 20-Apr-11 4:49am    
What you want to achive??
To run this code and create a List with your custom template programatically??

Am I right?
Rahul48 20-Apr-11 5:49am    
@code in play->i want to create custom list from vs2010. And want to add some field in that. say for custid and customername
i want to field up these customfield programatically. but while adding the customlist definiation from VS2010.
there is no file to write C# code in solution explorer. So how can write custom code.
What are steps to write custom?? Hope i explained my probs. Pls help me...
pankajupadhyay29 20-Apr-11 8:23am    
please use replay option to send a replay so that the other person could get notify.

1 solution

if you want to do this at the machine you are hsting the sharepoint then this could will work.

For this you can create a webpage ask all the parameters from user and when user click a create button excute this code(write this code on button click event)

hope this is solution for you otherwise just let me know then i want more clearification on your question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900