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.ComponentModel;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
using System.Web.UI.HtmlControls;


namespace FlashWebPart
{
    [Guid("f04fa49d-1342-4c7d-904a-c43ebc942f39")]
    [XmlRoot(Namespace = "FlashWebPart")]
    public class FlashWebPart : Microsoft.SharePoint.WebPartPages.WebPart
    {
        public FlashWebPart()
        {
            this.ExportMode = WebPartExportMode.All;
        }


        protected int flashWidth = 400;
        protected int flashHeight = 300;
        protected string flashUrl = "";
       
       
        [Browsable(true),
        Category("Flash Info"),
        DefaultValue(400),
        WebPartStorage(Storage.Shared),
        FriendlyName("Width"),
        Description("Width of the web part")]
        public int FlashWidth
        {
            get
            {
                return this.flashWidth;
            }
            set
            {
                this.flashWidth = value;
            }
        }

        [Browsable(true),
       Category("Flash Info"),
        DefaultValue(300),
        WebPartStorage(Storage.Shared),
        FriendlyName("Height"),
        Description("Height of the web part")]
        public int FlashHeight
        {
            get
            {
                return this.flashHeight;
            }
            set
            {
                this.flashHeight = value;
            }
        }

        [Browsable(true),
        Category("Flash Info"),
        DefaultValue(""),
        WebPartStorage(Storage.Shared),
        FriendlyName("URL"),
        Description("URL of the web part")]
        public string FlashURL
        {
            get
            {
                return this.flashUrl;
            }
            set
            {
                this.flashUrl = value;
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            string outHTML = "<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" " +
                        "codebase=

\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" " +
                        "WIDTH=" + flashWidth + " HEIGHT=" + flashHeight + "> " +
                        "<PARAM NAME=movie VALUE=\"" + flashUrl + "\"> " +
                        "<PARAM NAME=WMODE VALUE=\"Transparent\">" +
                        "<PARAM NAME=quality VALUE=high> " +
                        "<EMBED src=\"" + flashUrl +
                        "\" quality=high wmode=\"transparent\" WIDTH=\"" + flashWidth +
                        "\" HEIGHT=\"" + flashHeight +
                        "\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=

\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED> " +
                        "</OBJECT>";

            writer.Write(outHTML);
        }
    }
}

 

To apply this code, you will need SharePoint Services 3.0 extenstions for Visual studio  2005 to be installed, first create new SharePoint web part Project then override the web part class file. 

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
Dear Praveen,
Good Day,
First you need to download Windows SharePoint Services 3.0 Visual Studio 2005 Extensions

then Install it on your SharePoint Server, this will allow you to create SharePoint Webparts and Site definition. After installation create new WebPart Project then override the Web part class.
Comment By Mahdi Abdulhamid At 6/12/2007 1:07 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>