According to the samples in the MSDN article about the REST API in http://msdn.microsoft.com/en-us/library/office/jj860569(v=office.15).aspx, this code snippet could be used to read a web property from a SharePoint site.

static void Main(string[] args)
{
  string url = "http://server:6000";

  string restUrl = String.Format("{0}/_api/Web/AllProperties", url);

  //Create a namespace manager for parsing the ATOM XML returned by the queries.
  XmlNamespaceManager xmlnspm = new XmlNamespaceManager(new NameTable());

  //Add pertinent namespaces to the namespace manager.
  xmlnspm.AddNamespace("atom", "http://www.w3.org/2005/Atom");
  xmlnspm.AddNamespace("d", "http://schemas.microsoft.com/ado/2007/08/dataservices");
  xmlnspm.AddNamespace("m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata");

  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(restUrl);
  request.Credentials = System.Net.CredentialCache.DefaultCredentials;
  request.Method = "GET";
  request.Accept = "application/atom+xml";
  request.ContentType = "application/atom+xml;type=entry";

  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  StreamReader reader = new StreamReader(response.GetResponseStream());
  var valueXml = new XmlDocument();
  valueXml.LoadXml(reader.ReadToEnd());

  var propertyXml = valueXml.SelectSingleNode("//m:properties/d:MyProperty", xmlnspm);
  string value = propertyXml.InnerXml;

  Console.WriteLine(value);
}

Because this code uses System.Net.CredentialCache.DefaultCredentials for authentication, this code will not run with SharePoint sites in Office 365.

Advertisements