How to create a List in SharePoint using Client Object Model?

ClientContext clientContext = new ClientContext(“http://url”);

ListCreationInformation listCreationInformation = new ListCreationInformation();
listCreationInformation.Title = “New List Title”;
listCreationInformation.TemplateType = (int)ListTemplateType.Tasks;

list = clientContext.Web.Lists.Add(listCreationInformation);

clientContext.ExecuteQuery();

2 thoughts on “How to create a List in SharePoint using Client Object Model?

  1. Vinu Kumaran says:

    Hi,

    How to access datetime field of SharePoint list’s attribute inside a javascript function?

    I have a the datetime field “StartedOn”, how can I access the sharepoint datafield inside the javascript?

    I tried this by like this

    var ppe = document.getElementById(‘).value; (This is inside the Default.aspx page)

    But not working, any alternative will be much helpful.

    Vinu

    1. Jean Paul says:

      Hei Vinu Kumaran.. Nice to see you again my friend..

      You can try the following code as reference:
      listItem.get_item(‘StartedOn’)

      http://msdn.microsoft.com/en-us/library/gg701783.aspx

      function ReadListItem() {
      var listTitle = “Airports”;

      //Get the current client context
      context = SP.ClientContext.get_current();
      var airportList = context.get_web().get_lists().getByTitle(listTitle);

      var camlQuery = SP.CamlQuery.createAllItemsQuery();

      this.listItems = airportList.getItems(camlQuery);

      context.load(listItems);

      context.executeQueryAsync(ReadListItemSucceeded, ReadListItemFailed);
      }

      function ReadListItemSucceeded(sender, args) {
      var itemsString = ”;
      var enumerator = listItems.getEnumerator();

      while (enumerator.moveNext()) {
      var listItem = enumerator.get_current();
      itemsString += ‘AirportName: ‘ + listItem.get_item(‘AirportName’) +
      ‘ AirportCode: ‘ + listItem.get_id().toString() + ‘n’;
      }

      alert(itemsString);
      }

      function ReadListItemFailed(sender, args) {
      alert(‘Request failed. ‘ + args.get_message() + ‘n’ + args.get_stackTrace());
      }

Leave a Reply

Your email address will not be published. Required fields are marked *