Software Development Technologies and Solutions
SharePoint | .NET | MCMS | MS SQL | Office

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:

flash Web Part

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

Trackbacks :
http://devexpert.net/blog/pt/blog/track.aspx?id=18
Thanks dear, nice work.
Comment By mike III At 6/12/2007 5:29 AM
hi friend nice to see this article it is very good.but i am a person........unable to create webparts using vs2005 and wss3.0.......
can u give detail steps means i will feel very happy
Comment By praveen At 6/12/2007 12:06 PM
Do you have any solutions for people running it on the 64 bit servers (can't use the 2005 Extensions).
Comment By Matt At 8/8/2007 1:30 PM
Tried to execute the same code but not able to see the FlashInfo property tab....

However able to get the default properties tabs like Appearance, Advance ,....

Please suggest the solution ASAP
Comment By Rajiv Ranjan Giri At 11/22/2007 3:00 PM
Hello,
I am from Chile an need web parts flash, and don´t idea of program, is possible send a my mail the .dll or .cab
Comment By marco At 12/12/2007 9:58 AM
i have a propbelm deploying this web part where when i deployed it successfully only the default web part properties appeared and there was no hieght and width and SRC
Comment By mohammad olayyan At 2/28/2008 8:39 AM
Dear Mohamed,
I've replied this issue here:
http://www.codeproject.com/KB/sharepoint/MOSSFlashWebPart.aspx?msg=2095084#xx2095084xx
Comment By Mahdi Abdulhamid At 2/28/2008 9:36 AM
Comments :
Name :
Email :
URL :
       
Comments :
Allowed Tags : <A>, <B>, <I>, <BLOCKQUOTE>