I have a list A with columns and another List B column name same as List A, all are single line text and I...





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a list A with columns Title, Emp ID & Start Date and End Date, Designation, in List A I have some data, and another List B column name same as List A, all are single line text and I want to retrieve all the data which is in List A using Visual Studio.










share|improve this question































    1















    I have a list A with columns Title, Emp ID & Start Date and End Date, Designation, in List A I have some data, and another List B column name same as List A, all are single line text and I want to retrieve all the data which is in List A using Visual Studio.










    share|improve this question



























      1












      1








      1


      1






      I have a list A with columns Title, Emp ID & Start Date and End Date, Designation, in List A I have some data, and another List B column name same as List A, all are single line text and I want to retrieve all the data which is in List A using Visual Studio.










      share|improve this question
















      I have a list A with columns Title, Emp ID & Start Date and End Date, Designation, in List A I have some data, and another List B column name same as List A, all are single line text and I want to retrieve all the data which is in List A using Visual Studio.







      sharepoint office365 sharepoint-online






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 12:25









      Armali

      7,8001238107




      7,8001238107










      asked Jan 2 at 9:24









      ahsan95ahsan95

      63




      63
























          2 Answers
          2






          active

          oldest

          votes


















          0














          //Code

          using System.Net;
          using Microsoft.SharePoint.Client;

          using (ClientContext context = new ClientContext("http://yourserver.sharepoint.com/")) {
          context.Credentials = new NetworkCredential("user", "password", "domain");
          List announcementsList = context.Web.Lists.GetByTitle("List A");

          // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
          // so that it grabs all list items, regardless of the folder they are in.
          CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
          ListItemCollection items = announcementsList.GetItems(query);

          // Retrieve all items in the ListItemCollection from List.GetItems(Query).
          context.Load(items);
          context.ExecuteQuery();
          foreach (ListItem listItem in items)
          {
          // We have all the list item data. For example, Title.
          label1.Text = label1.Text + ", " + listItem["Title"];
          //label2.Text = label2.Text + ", " + listItem["Emp_x0020_ID"];

          //EMP_x0020_ID could be internal name of SharePoint list column "EMP ID"
          //Likewise check the column internal name for all the columns
          //To find internal name, go to list settings and click each column
          //you will see towards the end of the url something like &Field=Emp_x0020_ID
          //"Emp_x0020_ID" is the internal name of the field
          }
          }


          I hope this helps






          share|improve this answer
























          • I tried but getting error

            – ahsan95
            Jan 3 at 8:07











          • Any lead on urgently???

            – ahsan95
            Jan 3 at 8:17











          • Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

            – Lukas Nespor
            Jan 3 at 8:17













          • Thanks @Dhurba and Lukas and one give a best and simple ans

            – ahsan95
            Jan 4 at 5:13



















          0














          Your question is tagged with sharepoint-online so this code will work for you. Instead of NetworkCredential (as stated in answer by @Dhurba) you have to use SharePointOnlineCredentials.



          string userName = "";
          string password = "";
          string siteUrl = "https://tenant.sharepoint.com";

          using (ClientContext cc = new ClientContext(siteUrl))
          using (SecureString securedPassword = new SecureString())
          {
          password.ToList().ForEach(c => securedPassword.AppendChar(c));
          cc.Credentials = new SharePointOnlineCredentials(userName, securedPassword);

          // Load only server relative url
          cc.Load(cc.Web, p => p.ServerRelativeUrl);
          cc.ExecuteQuery();

          // Get list by url - better than by title, because title can be different in other languages
          List list = cc.Web.GetList($"{cc.Web.ServerRelativeUrl.TrimEnd('/')}/Lists/SomeListUrl");

          // Load all items even if the list contains more than 5000 items,
          // which is hard limit in SharePoint Online, using paggination
          CamlQuery query = CamlQuery.CreateAllItemsQuery(200);
          do
          {
          ListItemCollection items = list.GetItems(query);
          cc.Load(items);
          cc.ExecuteQuery();

          foreach (ListItem item in items)
          {
          Console.WriteLine($"ID: {item.Id} | {item["InternalNameOfColumn"]}");
          }

          // Set position info to query
          query.ListItemCollectionPosition = items.ListItemCollectionPosition;

          // When there are no other items the position info will be null
          } while (query.ListItemCollectionPosition != null);
          }


          Note:




          If you are using older Visual Studio than 2017, the interpolation $"{someVariable}" will not work and you will have to replace it with eg. string.Format("{0}", someVariable).







          share|improve this answer


























          • any other simple one

            – ahsan95
            Jan 3 at 8:49











          • @ahsan95 did it help?

            – Lukas Nespor
            Jan 3 at 9:53












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003876%2fi-have-a-list-a-with-columns-and-another-list-b-column-name-same-as-list-a-all%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          //Code

          using System.Net;
          using Microsoft.SharePoint.Client;

          using (ClientContext context = new ClientContext("http://yourserver.sharepoint.com/")) {
          context.Credentials = new NetworkCredential("user", "password", "domain");
          List announcementsList = context.Web.Lists.GetByTitle("List A");

          // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
          // so that it grabs all list items, regardless of the folder they are in.
          CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
          ListItemCollection items = announcementsList.GetItems(query);

          // Retrieve all items in the ListItemCollection from List.GetItems(Query).
          context.Load(items);
          context.ExecuteQuery();
          foreach (ListItem listItem in items)
          {
          // We have all the list item data. For example, Title.
          label1.Text = label1.Text + ", " + listItem["Title"];
          //label2.Text = label2.Text + ", " + listItem["Emp_x0020_ID"];

          //EMP_x0020_ID could be internal name of SharePoint list column "EMP ID"
          //Likewise check the column internal name for all the columns
          //To find internal name, go to list settings and click each column
          //you will see towards the end of the url something like &Field=Emp_x0020_ID
          //"Emp_x0020_ID" is the internal name of the field
          }
          }


          I hope this helps






          share|improve this answer
























          • I tried but getting error

            – ahsan95
            Jan 3 at 8:07











          • Any lead on urgently???

            – ahsan95
            Jan 3 at 8:17











          • Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

            – Lukas Nespor
            Jan 3 at 8:17













          • Thanks @Dhurba and Lukas and one give a best and simple ans

            – ahsan95
            Jan 4 at 5:13
















          0














          //Code

          using System.Net;
          using Microsoft.SharePoint.Client;

          using (ClientContext context = new ClientContext("http://yourserver.sharepoint.com/")) {
          context.Credentials = new NetworkCredential("user", "password", "domain");
          List announcementsList = context.Web.Lists.GetByTitle("List A");

          // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
          // so that it grabs all list items, regardless of the folder they are in.
          CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
          ListItemCollection items = announcementsList.GetItems(query);

          // Retrieve all items in the ListItemCollection from List.GetItems(Query).
          context.Load(items);
          context.ExecuteQuery();
          foreach (ListItem listItem in items)
          {
          // We have all the list item data. For example, Title.
          label1.Text = label1.Text + ", " + listItem["Title"];
          //label2.Text = label2.Text + ", " + listItem["Emp_x0020_ID"];

          //EMP_x0020_ID could be internal name of SharePoint list column "EMP ID"
          //Likewise check the column internal name for all the columns
          //To find internal name, go to list settings and click each column
          //you will see towards the end of the url something like &Field=Emp_x0020_ID
          //"Emp_x0020_ID" is the internal name of the field
          }
          }


          I hope this helps






          share|improve this answer
























          • I tried but getting error

            – ahsan95
            Jan 3 at 8:07











          • Any lead on urgently???

            – ahsan95
            Jan 3 at 8:17











          • Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

            – Lukas Nespor
            Jan 3 at 8:17













          • Thanks @Dhurba and Lukas and one give a best and simple ans

            – ahsan95
            Jan 4 at 5:13














          0












          0








          0







          //Code

          using System.Net;
          using Microsoft.SharePoint.Client;

          using (ClientContext context = new ClientContext("http://yourserver.sharepoint.com/")) {
          context.Credentials = new NetworkCredential("user", "password", "domain");
          List announcementsList = context.Web.Lists.GetByTitle("List A");

          // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
          // so that it grabs all list items, regardless of the folder they are in.
          CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
          ListItemCollection items = announcementsList.GetItems(query);

          // Retrieve all items in the ListItemCollection from List.GetItems(Query).
          context.Load(items);
          context.ExecuteQuery();
          foreach (ListItem listItem in items)
          {
          // We have all the list item data. For example, Title.
          label1.Text = label1.Text + ", " + listItem["Title"];
          //label2.Text = label2.Text + ", " + listItem["Emp_x0020_ID"];

          //EMP_x0020_ID could be internal name of SharePoint list column "EMP ID"
          //Likewise check the column internal name for all the columns
          //To find internal name, go to list settings and click each column
          //you will see towards the end of the url something like &Field=Emp_x0020_ID
          //"Emp_x0020_ID" is the internal name of the field
          }
          }


          I hope this helps






          share|improve this answer













          //Code

          using System.Net;
          using Microsoft.SharePoint.Client;

          using (ClientContext context = new ClientContext("http://yourserver.sharepoint.com/")) {
          context.Credentials = new NetworkCredential("user", "password", "domain");
          List announcementsList = context.Web.Lists.GetByTitle("List A");

          // This creates a CamlQuery that has a RowLimit of 100, and also specifies Scope="RecursiveAll"
          // so that it grabs all list items, regardless of the folder they are in.
          CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
          ListItemCollection items = announcementsList.GetItems(query);

          // Retrieve all items in the ListItemCollection from List.GetItems(Query).
          context.Load(items);
          context.ExecuteQuery();
          foreach (ListItem listItem in items)
          {
          // We have all the list item data. For example, Title.
          label1.Text = label1.Text + ", " + listItem["Title"];
          //label2.Text = label2.Text + ", " + listItem["Emp_x0020_ID"];

          //EMP_x0020_ID could be internal name of SharePoint list column "EMP ID"
          //Likewise check the column internal name for all the columns
          //To find internal name, go to list settings and click each column
          //you will see towards the end of the url something like &Field=Emp_x0020_ID
          //"Emp_x0020_ID" is the internal name of the field
          }
          }


          I hope this helps







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 21:24









          DhrubaDhruba

          315




          315













          • I tried but getting error

            – ahsan95
            Jan 3 at 8:07











          • Any lead on urgently???

            – ahsan95
            Jan 3 at 8:17











          • Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

            – Lukas Nespor
            Jan 3 at 8:17













          • Thanks @Dhurba and Lukas and one give a best and simple ans

            – ahsan95
            Jan 4 at 5:13



















          • I tried but getting error

            – ahsan95
            Jan 3 at 8:07











          • Any lead on urgently???

            – ahsan95
            Jan 3 at 8:17











          • Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

            – Lukas Nespor
            Jan 3 at 8:17













          • Thanks @Dhurba and Lukas and one give a best and simple ans

            – ahsan95
            Jan 4 at 5:13

















          I tried but getting error

          – ahsan95
          Jan 3 at 8:07





          I tried but getting error

          – ahsan95
          Jan 3 at 8:07













          Any lead on urgently???

          – ahsan95
          Jan 3 at 8:17





          Any lead on urgently???

          – ahsan95
          Jan 3 at 8:17













          Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

          – Lukas Nespor
          Jan 3 at 8:17







          Instead of NetworkCredential you have to use SharePointOnlineCredentials. See my answer.

          – Lukas Nespor
          Jan 3 at 8:17















          Thanks @Dhurba and Lukas and one give a best and simple ans

          – ahsan95
          Jan 4 at 5:13





          Thanks @Dhurba and Lukas and one give a best and simple ans

          – ahsan95
          Jan 4 at 5:13













          0














          Your question is tagged with sharepoint-online so this code will work for you. Instead of NetworkCredential (as stated in answer by @Dhurba) you have to use SharePointOnlineCredentials.



          string userName = "";
          string password = "";
          string siteUrl = "https://tenant.sharepoint.com";

          using (ClientContext cc = new ClientContext(siteUrl))
          using (SecureString securedPassword = new SecureString())
          {
          password.ToList().ForEach(c => securedPassword.AppendChar(c));
          cc.Credentials = new SharePointOnlineCredentials(userName, securedPassword);

          // Load only server relative url
          cc.Load(cc.Web, p => p.ServerRelativeUrl);
          cc.ExecuteQuery();

          // Get list by url - better than by title, because title can be different in other languages
          List list = cc.Web.GetList($"{cc.Web.ServerRelativeUrl.TrimEnd('/')}/Lists/SomeListUrl");

          // Load all items even if the list contains more than 5000 items,
          // which is hard limit in SharePoint Online, using paggination
          CamlQuery query = CamlQuery.CreateAllItemsQuery(200);
          do
          {
          ListItemCollection items = list.GetItems(query);
          cc.Load(items);
          cc.ExecuteQuery();

          foreach (ListItem item in items)
          {
          Console.WriteLine($"ID: {item.Id} | {item["InternalNameOfColumn"]}");
          }

          // Set position info to query
          query.ListItemCollectionPosition = items.ListItemCollectionPosition;

          // When there are no other items the position info will be null
          } while (query.ListItemCollectionPosition != null);
          }


          Note:




          If you are using older Visual Studio than 2017, the interpolation $"{someVariable}" will not work and you will have to replace it with eg. string.Format("{0}", someVariable).







          share|improve this answer


























          • any other simple one

            – ahsan95
            Jan 3 at 8:49











          • @ahsan95 did it help?

            – Lukas Nespor
            Jan 3 at 9:53
















          0














          Your question is tagged with sharepoint-online so this code will work for you. Instead of NetworkCredential (as stated in answer by @Dhurba) you have to use SharePointOnlineCredentials.



          string userName = "";
          string password = "";
          string siteUrl = "https://tenant.sharepoint.com";

          using (ClientContext cc = new ClientContext(siteUrl))
          using (SecureString securedPassword = new SecureString())
          {
          password.ToList().ForEach(c => securedPassword.AppendChar(c));
          cc.Credentials = new SharePointOnlineCredentials(userName, securedPassword);

          // Load only server relative url
          cc.Load(cc.Web, p => p.ServerRelativeUrl);
          cc.ExecuteQuery();

          // Get list by url - better than by title, because title can be different in other languages
          List list = cc.Web.GetList($"{cc.Web.ServerRelativeUrl.TrimEnd('/')}/Lists/SomeListUrl");

          // Load all items even if the list contains more than 5000 items,
          // which is hard limit in SharePoint Online, using paggination
          CamlQuery query = CamlQuery.CreateAllItemsQuery(200);
          do
          {
          ListItemCollection items = list.GetItems(query);
          cc.Load(items);
          cc.ExecuteQuery();

          foreach (ListItem item in items)
          {
          Console.WriteLine($"ID: {item.Id} | {item["InternalNameOfColumn"]}");
          }

          // Set position info to query
          query.ListItemCollectionPosition = items.ListItemCollectionPosition;

          // When there are no other items the position info will be null
          } while (query.ListItemCollectionPosition != null);
          }


          Note:




          If you are using older Visual Studio than 2017, the interpolation $"{someVariable}" will not work and you will have to replace it with eg. string.Format("{0}", someVariable).







          share|improve this answer


























          • any other simple one

            – ahsan95
            Jan 3 at 8:49











          • @ahsan95 did it help?

            – Lukas Nespor
            Jan 3 at 9:53














          0












          0








          0







          Your question is tagged with sharepoint-online so this code will work for you. Instead of NetworkCredential (as stated in answer by @Dhurba) you have to use SharePointOnlineCredentials.



          string userName = "";
          string password = "";
          string siteUrl = "https://tenant.sharepoint.com";

          using (ClientContext cc = new ClientContext(siteUrl))
          using (SecureString securedPassword = new SecureString())
          {
          password.ToList().ForEach(c => securedPassword.AppendChar(c));
          cc.Credentials = new SharePointOnlineCredentials(userName, securedPassword);

          // Load only server relative url
          cc.Load(cc.Web, p => p.ServerRelativeUrl);
          cc.ExecuteQuery();

          // Get list by url - better than by title, because title can be different in other languages
          List list = cc.Web.GetList($"{cc.Web.ServerRelativeUrl.TrimEnd('/')}/Lists/SomeListUrl");

          // Load all items even if the list contains more than 5000 items,
          // which is hard limit in SharePoint Online, using paggination
          CamlQuery query = CamlQuery.CreateAllItemsQuery(200);
          do
          {
          ListItemCollection items = list.GetItems(query);
          cc.Load(items);
          cc.ExecuteQuery();

          foreach (ListItem item in items)
          {
          Console.WriteLine($"ID: {item.Id} | {item["InternalNameOfColumn"]}");
          }

          // Set position info to query
          query.ListItemCollectionPosition = items.ListItemCollectionPosition;

          // When there are no other items the position info will be null
          } while (query.ListItemCollectionPosition != null);
          }


          Note:




          If you are using older Visual Studio than 2017, the interpolation $"{someVariable}" will not work and you will have to replace it with eg. string.Format("{0}", someVariable).







          share|improve this answer















          Your question is tagged with sharepoint-online so this code will work for you. Instead of NetworkCredential (as stated in answer by @Dhurba) you have to use SharePointOnlineCredentials.



          string userName = "";
          string password = "";
          string siteUrl = "https://tenant.sharepoint.com";

          using (ClientContext cc = new ClientContext(siteUrl))
          using (SecureString securedPassword = new SecureString())
          {
          password.ToList().ForEach(c => securedPassword.AppendChar(c));
          cc.Credentials = new SharePointOnlineCredentials(userName, securedPassword);

          // Load only server relative url
          cc.Load(cc.Web, p => p.ServerRelativeUrl);
          cc.ExecuteQuery();

          // Get list by url - better than by title, because title can be different in other languages
          List list = cc.Web.GetList($"{cc.Web.ServerRelativeUrl.TrimEnd('/')}/Lists/SomeListUrl");

          // Load all items even if the list contains more than 5000 items,
          // which is hard limit in SharePoint Online, using paggination
          CamlQuery query = CamlQuery.CreateAllItemsQuery(200);
          do
          {
          ListItemCollection items = list.GetItems(query);
          cc.Load(items);
          cc.ExecuteQuery();

          foreach (ListItem item in items)
          {
          Console.WriteLine($"ID: {item.Id} | {item["InternalNameOfColumn"]}");
          }

          // Set position info to query
          query.ListItemCollectionPosition = items.ListItemCollectionPosition;

          // When there are no other items the position info will be null
          } while (query.ListItemCollectionPosition != null);
          }


          Note:




          If you are using older Visual Studio than 2017, the interpolation $"{someVariable}" will not work and you will have to replace it with eg. string.Format("{0}", someVariable).








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 11:08

























          answered Jan 3 at 8:15









          Lukas NesporLukas Nespor

          9641918




          9641918













          • any other simple one

            – ahsan95
            Jan 3 at 8:49











          • @ahsan95 did it help?

            – Lukas Nespor
            Jan 3 at 9:53



















          • any other simple one

            – ahsan95
            Jan 3 at 8:49











          • @ahsan95 did it help?

            – Lukas Nespor
            Jan 3 at 9:53

















          any other simple one

          – ahsan95
          Jan 3 at 8:49





          any other simple one

          – ahsan95
          Jan 3 at 8:49













          @ahsan95 did it help?

          – Lukas Nespor
          Jan 3 at 9:53





          @ahsan95 did it help?

          – Lukas Nespor
          Jan 3 at 9:53


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54003876%2fi-have-a-list-a-with-columns-and-another-list-b-column-name-same-as-list-a-all%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          SQL update select statement

          'app-layout' is not a known element: how to share Component with different Modules