How to Insert notepad data into CustomList In SharePoint 2010

            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
 

No comments:

Post a Comment