Thursday, November 5, 2009

SharePoint Media Player Webpart in Silvelight 2.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
using System.Web.UI;
using System.Web;


namespace MediaPlayerWP
{
public class MediaPlayer:WebPart
{
#region "Global variable declarations"

protected string _exception = String.Empty;

#endregion


#region "Create Child Controls method to create the controls for the webpart"

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager == null)
{
scriptManager = new ScriptManager();
this.Controls.Add(scriptManager);
}

}
protected override void CreateChildControls()
{
try
{
System.Web.UI.SilverlightControls.Silverlight myMediaCtrl = new System.Web.UI.SilverlightControls.Silverlight();
myMediaCtrl.ID = "myMediaPlayer";
myMediaCtrl.Source = "/ClientBin/XAP/MediaPlayer.xap";
myMediaCtrl.Width = new System.Web.UI.WebControls.Unit(900);
myMediaCtrl.Height = new System.Web.UI.WebControls.Unit(650);

this.Controls.Add(myMediaCtrl);

}
catch (Exception ex)
{
_exception += "CREATE ERROR:" + ex.Message;
}
finally
{
base.CreateChildControls();
}
}
#endregion

#region "RenderControls method , to render the controls inside the webpart class"

protected override void RenderContents(HtmlTextWriter writer)
{
try
{
base.RenderContents(writer);
}
catch (Exception ex)
{
_exception += "RENDER ERROR:" + ex.Message;
}
}

#endregion
}
}

No comments:

Post a Comment