Creating CustomList with Columns in Object Model
Creating Custom List
with Fields:
Steps to Create
Project:
Go to -> Start menu -> visual studio 2010 -> select
new Project -> select c# -> Console Application -> select Class1.cs Template.
Give the Name for
the project as StudentsList ->
Click Ok.
With in the Solution Explorer
-> Right Click on StudentsList Name.
Select Addreference… -> select Browse Tab. -> then Go To
sharepoint root Directory for adding the Microsoft.Sharepoint.Dll
Reference file.
Path = C:\Program
Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI
Then select the Microsoft.Sharepoint.Dll
file then click Ok. The Reference
file will be added to your project.
Then Go to Class1.CS file.
And Write Code As shown bellow.
Aim:Creating Students List With StudentName Field
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
using
Microsoft.SharePoint;
namespace ListData
{
class Program
{
static void Main(string[] args)
{
SPSite site = new
SPSite("http://sp2010:6060/SitePages/Home.aspx");
SPWeb web = site.OpenWeb();
//Creating
Student List
web.Lists.Add("Students",
"This list created using code", SPListTemplateType.GenericList);
SPList list =
web.Lists["Students"];
list.OnQuickLaunch = true;
list.Update();
//Creating
Student Fields
SPField titleField =
list.Fields["Title"];
titleField.Title =
"StudentName";
titleField.Update();
}
}
}
goto Build Tab -> select BuildSolution
goto Debug Tab -> select StartDebugging (OR) Press F5 Key.
Out Put:
goto u r site URL:http://sp2010:6060/SitePages/Home.aspx
with in that u can sea the Students List with StudentName Column.
Comments
Post a Comment