Tuesday, June 15, 2010

SharePoint Flash WebPart !

Looking for an easier way to add a Flash file to a SharePoint content page? Download and install the Flash WebPart SharePoint Solution and you will be able to add Flash movies to your SharePoint web pages without having to edit any html code. Simply add the Flash WebPart to a page, configure it in the WebPart editor by setting the movie URL, width, and height, and you are good to go.

Download the Flash WebPart (SharePoint Solution)

Download the Flash WebPart Source Code (C# with all Solution Assets)

Flash WebPart Installation

1. Unzip FlashWebPart.MikeKnowles.zip

2. Follow the instructions in Readme.txt to install the SharePoint solution to your SharePoint farm.

3. The installation will prompt you to optionally install the Flash WebPart feature to one or more Site Collections. It’s highly recommended that you deploy to the Site Collections during the install process as its quicker then having to activate the feature in each site individually.

Using the Flash WebPart

1. If necessary, activate the Feature in the target Site Collection. If you installed the Feature to the Site Collection when you ran the setup program above then you can skip this step.

2. Within the target Site Collection, open a SharePoint page which contains a WebPart Zone and select:
Site Actions > Edit Page

3. Click to Add a Web Part, and select the SharePoint Flash WebPart as shown below:


4. Click Edit > Modify Shared Part


5. Within the WebPart Editor, scroll down and click to open the Miscellaneous tab:


6. Enter the Flash URL, width, and height of your Flash Movie (SWF). Here are some test values to get you started:

Flash URL: http://www.adobe.com/products/flashplayer/include/marquee/design.swf
Flash Width: 792
Flash Height: 294

C# Source-Code Overview (For SharePoint Developers)

The C# source-code is packaged as a SharePoint solution and was built using Visual Studio 2008,
CodePlex WSPBuilder, and the Google Code Babel Obfuscator.

1. Download and Install CodePlex WSPBuilder

2. Download and Install Google Code Babel Obfuscator

3. Add WSPBuilder and Babel to your System path:
C:\Program Files\Babel;C:\Program Files\WSPTools\WSPBuilderExtensions;

* Note: if you skip the above steps, you can still view the source however it will fail if you build the solution) *

4. Extract the source code download and open the Visual Studio 2008 solution: MikeKnowles.FlashWebPart.sln


5. Build the Solution. The code is compiled as a class library, and then a post-build event runs to execute WSPBuilder to generate the MikeKnowles.FlashWebPart.wsp SharePoint solution package. If a release build is in effect, then the post-build script executes Babel Obfuscator to prevent reverse-engineering of the .NET CIL with tools such as ILDASM and Reflector. This technique is moot in this context since I have provided you with all the source code. The point is that Babel Obfuscator can be used for more security-sensitive development projects to help protect your source code from being examined or copied using a reflection tool.

The key source code files to examine are the post-build event and the C# class file which provides the Flash WebPart and its accompanying editor functions.

MikeKnowles.FlashWebPart.csproj Post-Build Event

if /I "$(ConfigurationName)" == "Release" babel.exe -v 2 --noinvalidopcodes --ildasm --statistics --nodeadcode --output $(TargetPath) --kf $(ProjectDir)$(ProjectName).snk $(TargetPath) WSPBuilder.exe -WSPName $(ProjectName).wsp -ProjectPath $(ProjectDir) -Outputpath $(ProjectDir) -DeploymentTarget GAC


public class FlashWebPart : System.Web.UI.WebControls.WebParts.WebPart, IWebEditable { private string flashUrl; private int flashWidth; private int flashHeight; [WebBrowsable(true)] [Personalizable(PersonalizationScope.Shared)] [WebDisplayName("Flash URL")] [WebDescription("URL Path to load and display the Flash (SWF) file")] public string FlashUrl { get { return flashUrl; } set { flashUrl = value; } } [WebBrowsable(true)] [Personalizable(PersonalizationScope.Shared)] [WebDisplayName("Flash Width")] [WebDescription("Width in pixels for display of the Flash file")] public int FlashWidth { get { return flashWidth; } set { flashWidth = value; } } [WebBrowsable(true)] [Personalizable(PersonalizationScope.Shared)] [WebDisplayName("Flash Height")] [WebDescription("Height in pixels for display of the Flash file")] public int FlashHeight { get { return flashHeight; } set { flashHeight = value; } } public FlashWebPart() { this.ExportMode = WebPartExportMode.All; } private string GetHtml() { StringBuilder sb = new StringBuilder(); sb.Append("<span id="preserveec270f02408d4338b4ae4fbfc918e81c" class="wlWriterPreserve"><OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" "); sb.Append("codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" "); sb.Append("WIDTH=\"" + this.FlashWidth + "\" HEIGHT=\"" + this.FlashHeight + "\"> "); sb.Append("<PARAM NAME="\"movie\"" VALUE="\""" + this.FlashUrl + "\"> "); sb.Append("<PARAM NAME="\"WMODE\"" VALUE="\"Transparent\"">"); sb.Append("<PARAM NAME="\"quality\"" VALUE="\"high\""> "); sb.Append("<EMBED src="\""" + this.FlashUrl); sb.Append("\" quality=\"high\" wmode=\"transparent\" WIDTH=\"" + this.FlashWidth); sb.Append("\" HEIGHT=\"" + this.FlashHeight); sb.Append("\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED> "); sb.Append("</OBJECT></span>"); return sb.ToString(); } protected override void Render(HtmlTextWriter writer) { base.Render(writer); writer.Write(GetHtml()); } }

Mike Knowles - SharePoint Flash WebPart

No comments:

Post a Comment