Hide
Writing an article is easy - try our reStructured Text demo Join Siafoo Now or Learn More

Web Part Hosted Silverlight Control - Page Atom Feed 0

# 's
 1using System;
2using System.Linq;
3using System.Net;
4using System.Windows;
5using System.Windows.Browser;
6using System.Windows.Controls;
7using System.Xml.Linq;
8
9namespace DagRegistrations
10{
11 public partial class Page : UserControl
12 {
13 private string m_dataUrl;
14 private XDocument m_xdoc;
15
16 /// <summary>
17 /// Constructor
18 /// </summary>
19 /// <param name="dataUrl"></param>
20 public Page(string listGuid)
21 {
22 if (string.IsNullOrEmpty(listGuid))
23 throw new ArgumentNullException("listGuid");
24
25 string baseUrl = string.Concat(HtmlPage.Document.DocumentUri.Scheme, "://", HtmlPage.Document.DocumentUri.GetComponents(UriComponents.HostAndPort, UriFormat.UriEscaped));
26 Guid lg = new Guid(listGuid);
27
28 // e.g. "http://server1:23092/_vti_bin/owssvr.dll?Cmd=Display&List=%7B34D14716%2D137B%2D450E%2DBC36%2DD0580B47857C%7D&XMLDATA=TRUE"
29 m_dataUrl = string.Concat(baseUrl, "/_vti_bin/owssvr.dll?Cmd=Display&List=", HttpUtility.UrlEncode(lg.ToString()), "&XMLDATA=TRUE");
30
31 InitializeComponent();
32 Loaded += new RoutedEventHandler(Page_Loaded);
33 }
34
35 /// <summary>
36 /// Page loaded event
37 /// </summary>
38 /// <param name="sender"></param>
39 /// <param name="e"></param>
40 private void Page_Loaded(object sender, RoutedEventArgs e)
41 {
42 // Credentials will be taken from the current IE user
43 WebClient svc = new WebClient();
44 svc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(XmlDownloadStringCompleted);
45 svc.DownloadStringAsync(new Uri(m_dataUrl, UriKind.Absolute));
46 }
47
48 /// <summary>
49 /// XML list data download complete
50 /// </summary>
51 /// <param name="sender"></param>
52 /// <param name="e"></param>
53 private void XmlDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
54 {
55 // e.result contains Xml string
56 m_xdoc = XDocument.Parse(e.Result);
57 InitializeGrid();
58 }
59
60 /// <summary>
61 /// Set up the grid
62 /// </summary>
63 private void InitializeGrid()
64 {
65 // The Task object is a simple data class to roll yourself with the properties you need
66 XNamespace z = "#RowsetSchema";
67 var myData = from row in m_xdoc.Descendants(z + "row")
68 select new Task
69 {
70 Title = row.Attribute("ows_LinkTitle") != null ? row.Attribute("ows_LinkTitle").Value : null,
71 AssignedTo = row.Attribute("ows_AssignedTo") != null ? row.Attribute("ows_AssignedTo").Value : null,
72 Status = row.Attribute("ows_Status") != null ? row.Attribute("ows_Status").Value : null,
73 Priority = row.Attribute("ows_Priority") != null ? row.Attribute("ows_Priority").Value : null,
74 DueDate = row.Attribute("ows_DueDate") != null ? Convert.ToDateTime(row.Attribute("ows_DueDate").Value) : DateTime.Now,
75 };
76
77 myDataGrid.ItemsSource = myData;
78 }
79 }
80}