Client Object Model (OM)

Table of Contents

Available for:

  • .NET CLR
  • Silverlight
  • JavaScript

Semantics of code is designed to be as close as possible for each runtime.

.NET CLR

Requires adding references Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.

Unable to find source-code formatter for language: csharp. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
ClientContext clientCtx = new ClientContext("http://moss");
Web site = clientCtx.Web;
clientCtx.Load(site);
clientCtx.ExecuteQuery();
site.Title += "updated by Client OM";
site.Update();
clientCtx.ExecuteQuery();

JavaScript

<script language="javascript" type="text/javascript">
      ExecuteOrDelayUntilScriptLoaded(Initialize, "SP.js");

      var site;
      var context;
      function Initialize() {
          context = SP.ClientContext.get_current();
          site = context.get_web();
          context.load(site, "Title");
          context.executeQueryAsync(Succeeded, Failed);
      }
      function Succeeded(sender, args) {
          alert(site.get_title());
          site.set_title(site.get_title() + ' from js');
          site.update();
          context.executeQueryAsync(Succeeded2, Failed);
      }
      function Succeeded2(sender, args) {
          alert('Site Title Changed');
      }
      function Failed(sender, args) {
          alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
      }
</script>

External References

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare