Programming Against a List Using the Lists Web Service

Hai,

Here am going to program against lists in Share Point, which enables to manage Create, read, update and delete (CRUD) operations against the list. To do this follow the steps.

Here we assume we have a list which already created in Share Point Portal. Assume the list name as \”StudentDetails\” and it has columns like StudentName, FatherName, and Address.

Now create project in Visual studio, you can create any type of project either ASP.NET application or WPF application. Create a form which will take Student Name, Father Name and address.

So now we have a form which will take details and Share Point List to create/update details. we can access share Point List in programming through web services only so first will create web reference for Shape Point services.

  • Go to Project Node, and select Add Service Reference.
  • On the Add Service Reference dialog, click the Advanced button and then click Add Web Reference on the Service Reference Settings dialog.
  • In the Add Web Reference dialog, click the Web services on the local machine link.
  • This will search for and display all of the Web services that are located on your developer machine, which will include the SharePoint Web services. One of the Web services is the Lists service (with the endpoint listed as http://<server name>/_vti_bin/Lists.asmx).
  • Select this service.

By using this list service we can push data to Share Point List. When we call the Lists Web service, we need to create an XML construct that passes the data from application to SharePoint list. This XML is called the Collaborative Application Markup Language(CAML). 

The following code snippet illustrates the Add details to List

using System.Windows;
  using System.Xml;
  using WPF_Lists_WebService.SPListsService;
 
  namespace WPF_Lists_WebService
  {
      /// <summary>
      /// Interaction logic for MainWindow.xaml
      /// </summary>
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
          }
 
          private void btnUpdate_Click(object sender, RoutedEventArgs e)
          {
              var listService = new Lists { Credentials = System.Net.CredentialCache.DefaultCredentials, Url = \"http://siva-pc:46006//VSSiteDef/_vti_bin/Lists.asmx\" };
 
              XmlNode listView = listService.GetListAndView(\"Customers\", \"\");
 
              string listId = listView.ChildNodes[0].Attributes[\"Name\"].Value;
              string viewId = listView.ChildNodes[1].Attributes[\"Name\"].Value;
 
              XmlDataDocument listDoc = new XmlDataDocument();
              XmlElement batchXML = listDoc.CreateElement(\"Batch\");
 
              batchXML.InnerXml = \"<Method ID=\'1\' Cmd=\'New\'><Field Name=\'StudentName\'>\" + txtStudentName.Text + \"</Field><Field Name=\'FatherName\'>\" + txtFatherName.Text + \"</Field><Field Name=\'Address\'>\" + txtAddress.Text + \"</Field>\"+\"</Method>\";
 
              XmlNode listReturn = listService.UpdateListItems(listId, batchXML);
              MessageBox.Show(\"Share Point List Updated\");
          }
      }
  }

Leave a Reply

Scroll to Top
%d bloggers like this: