Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

    Advertisements
  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand
  • Advertisements

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

Posted by Paul on June 30, 2012


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();

Advertisements

2 Responses to “How to create a List in SharePoint using Client Object Model?”

  1. Vinu Kumaran said

    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

    • Jean Paul said

      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

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s