Silverlight Hosting Web Part
| In Brief | Host a Silverlight control in a SharePoint web part. |
| Language | C# |
# '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 [Personalizable(PersonalizationScope.Shared), WebBrowsable(true)]
30 public string MediaLibraryControlFileName
31 {
32 get { return m_mediaLibraryControlFileName; }
33 set { m_mediaLibraryControlFileName = value; }
34 }
35
36 [Personalizable(PersonalizationScope.Shared), WebBrowsable(true)]
37 public string ListGuid
38 {
39 get { return m_listGuid; }
40 set { m_listGuid = value; }
41 }
42
43 protected override void OnInit(EventArgs e)
44 {
45 base.OnInit(e);
46
47 ScriptManager sm = ScriptManager.GetCurrent(this.Page);
48 if (sm == null)
49 {
50 sm = new ScriptManager();
51 Controls.AddAt(0, sm);
52 }
53 }
54
55 protected override void CreateChildControls()
56 {
57 base.CreateChildControls();
58
59 Panel p = new Panel();
60 p.Style[HtmlTextWriterStyle.Width] = "100%";
61 p.Style[HtmlTextWriterStyle.TextAlign] = "Center";
62 System.Web.UI.SilverlightControls.Silverlight ctrl = new System.Web.UI.SilverlightControls.Silverlight();
63 ctrl.ID = "LazyLoadedControl";
64 ctrl.Source = string.Concat(SPContext.Current.Site.Url, this.MediaLibraryControlFileName);
65 ctrl.Width = this.Width;
66 ctrl.Height = this.Height;
67 ctrl.InitParameters = string.Concat("listGuid=", this.ListGuid);
68 p.Controls.Add(ctrl);
69 Controls.Add(p);
70 }
71 }
72}
Host a Silverlight control in a SharePoint web part.
Add a Comment