|
Hi everyone, I've seen that many people are using HTML content web part for displaying Flash animation, I don't recommend this approach for many reasons, one of them being you won't tell your client to edit HTML code for changing Flash properties; so it is better to have a dedicated web part for rendering Flash animation, I've developed a simple one, here is the code:

using System; using System.Runtime.InteropServices; using System.Web.UI; using System.Web.UI.WebControls.WebParts; using System.Xml.Serialization; using System.Text;
using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using Microsoft.SharePoint.WebPartPages;
namespace FlashWP { [Guid("859a6d18-dcc2-430f-9873-f414d49839a4")] public class FlashWP : System.Web.UI.WebControls.WebParts.WebPart { public FlashWP() { } private int flashWidth = 300; private int flashHeight = 200; private string flashUrl;
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Width"), WebDescription("Width of the flash")] public int FlashWidth { get { return flashWidth; } set { flashWidth = value; } }
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("Height"), WebDescription("Height of the flash")] public int FlashHeight { get { return flashHeight; } set { flashHeight = value; } }
[Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("URL"), WebDescription("Url of the flash file")] public string FlashUrl { get { return flashUrl; } set { flashUrl = value; } }
protected override void Render(HtmlTextWriter writer) { if (!String.IsNullOrEmpty(FlashUrl)) { StringBuilder _outstring = new StringBuilder();
_outstring.Append("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "); _outstring.Append("codebase=\"
http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" "); _outstring.Append("WIDTH="); _outstring.Append(flashWidth.ToString() ); _outstring.Append(" HEIGHT=" ); _outstring.Append(flashHeight.ToString()); _outstring.Append("> " ); _outstring.Append("<PARAM NAME=movie VALUE=\""); _outstring.Append(flashUrl ); _outstring.Append("\"> " ); _outstring.Append("<PARAM NAME=WMODE VALUE=\"Transparent\">"); _outstring.Append("<PARAM NAME=quality VALUE=high> " ); _outstring.Append("<EMBED src=\"" ); _outstring.Append(flashUrl ); _outstring.Append("\" quality=high wmode=\"transparent\" WIDTH=\""); _outstring.Append(flashWidth.ToString() ); _outstring.Append("\" HEIGHT=\"" ); _outstring.Append(flashHeight.ToString() ); _outstring.Append("\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"
http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED> "); _outstring.Append("</OBJECT>"); writer.Write(_outstring.ToString()); } else { writer.Write("Modify Webpart to add content URL"); } } } }
To apply this code, you will need SharePoint Services 3.0 extenstions for Visual studio 2005 to be installed.
Download source here
|