I want to retrieve data from sharepoint list using c# and store them into SQL server DB tables. How can I do this? -


string strurl = "some url";         using (spsite osite = new spsite(strurl))         {             using (spweb oweb = osite.openweb())             {                 splist list = oweb.lists["targetlist"];                  foreach (spfield field in list.fields)                 {                     console.writeline(field.title);                 }             }         } 

this code entering break state showing "file not found exception" .dont know problem is. want parse sharepoint list. after how insert data tables created in database

        string strurl = "some url";         using (spweb myweb = new spsite(strurl).openweb())         {                 splistitemcollection items = myweb.lists["yourlistname"].items;                  string fieldvalue1 = "";                 //...                 string fieldvaluen = "";                 sqlconnection con = new sqlconnection("connection string");                 cmd.connection = con;                  using (sqlcommand cmd = new sqlcommand())                 {                     con.open();                     foreach (splistitem item in items)                     {                         fieldvalue1 = item["column 1 name in splist"].tostring();                         //...                         fieldvaluen = item["column n name in splist"].tostring();                          string sqlcommand = "insert table_name(field1columnname, ..., fieldncolumnname) values('" + fieldvalue1 + "', ...,'" + fieldvalue1 + "')";                          cmd.commandtext = sqlcommand;                          cmd.executenonquery();                     }                      con.close();                 }          } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -