Hide
Bored? Check out the Recent Activity on Siafoo Join Siafoo Now or Learn More

Silverlight Hosting Web Part Atom Feed 0

In Brief Host a Silverlight control in a SharePoint web part.
# 's
 1using System;
2using System.Runtime.InteropServices;
3using System.Web.UI;
4using System.Web.UI.WebControls;
5using System.Web.UI.WebControls.WebParts;
6using System.Xml.Serialization;
7
8using Microsoft.SharePoint;
9using Microsoft.SharePoint.WebControls;
10using Microsoft.SharePoint.WebPartPages;
11using System.IO;
12using System.Xml.Schema;
13using System.Xml;
14using System.Net;
15
16namespace DagReportingWebPart
17{
18 [Guid("0e816c20-c0dd-4376-9529-abcbcde145b6")]
19 public class DagReporting : System.Web.UI.WebControls.WebParts.WebPart
20 {
21 public DagReporting()
22 {
23 }
24
25 protected string m_mediaLibraryControlFileName = string.Empty;
26 protected string m_listGuid = string.Empty;
27 protected string m_webUrl = string.Empty;
28
29 // e.g. /Docs/MySilverlightControl.xap
30 [Personalizable(PersonalizationScope.Shared), WebBrowsable(true)]
31 public string MediaLibraryControlFileName
32 {
33 get { return m_mediaLibraryControlFileName; }
34 set { m_mediaLibraryControlFileName = value; }
35 }
36
37 // Just a guid string
38 [Personalizable(PersonalizationScope.Shared), WebBrowsable(true)]
39 public string ListGuid
40 {
41 get { return m_listGuid; }
42 set { m_listGuid = value; }
43 }
44
45 protected override void OnInit(EventArgs e)
46 {
47 base.OnInit(e);
48
49 ScriptManager sm = ScriptManager.GetCurrent(this.Page);
50 if (sm == null)
51 {
52 sm = new ScriptManager();
53 Controls.AddAt(0, sm);
54 }
55 }
56
57 protected override void CreateChildControls()
58 {
59 base.CreateChildControls();
60
61 Panel p = new Panel();
62 p.Style[HtmlTextWriterStyle.Width] = "100%";
63 p.Style[HtmlTextWriterStyle.TextAlign] = "Center";
64 System.Web.UI.SilverlightControls.Silverlight ctrl = new System.Web.UI.SilverlightControls.Silverlight();
65 ctrl.ID = "LazyLoadedControl";
66 ctrl.Source = string.Concat(SPContext.Current.Site.Url, this.MediaLibraryControlFileName);
67 ctrl.Width = this.Width;
68 ctrl.Height = this.Height;
69
70 // Passed args to Silverlight. Comma delimitted list of string args can be used.
71 ctrl.InitParameters = string.Concat("listGuid=", this.ListGuid);
72 p.Controls.Add(ctrl);
73 Controls.Add(p);
74 }
75 }
76}

Host a Silverlight control in a SharePoint web part.