How to Insert Flat Data into CustomList In SharePoint 2010

InfoPath alternatives for form designing SharePoint

In this article we will discuss how to insert flat data into custom list in sharepoint 2010. Flat data means suppose the data is in notepad like below:

1 IT 10
2 Gov 20

Also you can see some SharePoint 2010 object model articles and List and Library articles here.

SPWeb web = new SPSite(“http://demo:500/”).OpenWeb();

SPList empList = web.Lists[“Dept”];

SPListItem item;

StreamReader sr = new StreamReader(“C:\\a.txt”);

while (sr.Peek() != -1)
{

string record = sr.ReadLine();

string[] data=record.Split(‘ ‘);

item=empList.Items.Add();

item[“Title”]=data[0];

item[“DeptName”]=data[1];

item[“DeptId”]=data[2];

item.Update();


}

In Notepad:
1 IT 10
2 Gov 20


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply