Monday, March 22, 2010

Read xml from web page and bind the data to Silverlight module

we build an architecture that SharePoint will build the XML for us and write it on the page and Silverlight grabs the XML from the page and displays the images on the UI. How nice it is. You can get the first part i.e. get xml (image) data from the SharePoint libraries

Here, we are discussing about the code we need to place in Page.xaml.cs file to read xml from web page.

 public Page() 
   { 
   string controlid = "divImgs"; //You can also use intiparams of Silverlight params to get the id. 
   InitializeComponent(); 
   
   string xmlstring = string.Empty; 
    if (controlid != null) 
  { 
   HtmlElement ctl = HtmlPage.Document.GetElementById(controlid); 
  if (ctl != null) 
  xmlstring = (string)ctl.GetProperty("innerHTML"); 
   } 
    
   if (!string.IsNullOrEmpty(xmlstring)) 
   { 
   ProcessXML(xmlstring); 
   } 
   }