Using the Visual Studio 2008 Extensions for SharePoint
I did a three (3) part Post on Developing and Deploying a Flash Animation Web Part for WSS and MOSS 2007. In that laborious process we created the Web Part DLL, we created a project to hold the Web Part Files and then we used STSADM tools to deploy it. While that brute force may be fun for some, SharePoint does have an easier way if you are developing in Visual Studio 2008 as I am. In fact in this Post I am also using the recommended way of creating Web Part Controls; in my previous post I used the Render Method with the HTMLTextWriter, using that method does not allow me ‘at a minimum’ to interrogate and interact with the Event Handlers at runtime. So in this post I am using the CreateChildObject Method…
What you will Need!
- Visual Studio 2008
- Project 1 – An Empty Project out of the VS 2008 Extensions Template
- Visual Studio 2008 Extensions for SharePoint
- WSS 3.0 or MOSS 2007
- A working knowledge of
- WSS 3.0 / MOSS 2007 Object Model
- Time… this time it took me a little under two hours to get this to work and do all my screen shots. But I have the advantage of just cutting and pasting my code from my earlier projects.
First you will need to Install the Visual Studio 2008 Extensions for SharePoint; this provides additional templates suited for WSS and MOSS development, along with scripts to Add and Deploy solutions to the MOSS solutions store.
Step 1: Create a New Project, I did an empty project rather than beginning with the Web Part Project. So… you may ask, why?… Well I have found that when I begin with a Web Part Project it creates an automatic folder called WebPart1 and supporting files with the same name. I have tried to rename the Folder and Files, but that proved to be too much work. So I create an empty project and ADD a web Part to the solution; this provides me the ability to name my folder thus keeping the name personalized from Jump!
Below is the Solution View of the Project. Notice it has the Strong Name already created.
Below is the WSP view (tagged next to the Solution Explorer) where you can see the Files necessary to deploy the Web Part to the Solution Store. In essence all the files I created by hand in the Part 1 through Part 3 Blog earlier. Its good practice to do it by hand because in this process you dont even touch the code and if something breaks you will have no knowledge how to fix it.
So the first thing you need to do is Code for your Web Part, since I already did this Brute Force, I am going to cut and paste my Property Gets and Sets to talk to set my Width, Height and swf Url location. Notice also now in the Solution Explorer you have all the files automatically created for you. Oops, one more thing I need to mention that I didn’t capture in the image below is a reference and inheritance to the System.ComponentModel [using System.ComponentModel;] this is needed so you can access your Property Procedures in your Web Part. But I corrected that in the smaller image below.
So now I am just going to cheat and cut and paste my Property Procedures as seen below.
So this is where we make some improvement on how we implemented the Flash Animation. This time we will use the CreateChildControls Method.
Deployment now is a piece of cake, you just have to point your "Start Action" in your Project Properties Debug Tab to the URL of the Top Level Site Collection that you want to deploy your solution to. See below.
Right click your Project in the Solutions Explorer and regular Click on Deploy… the VS 2008 Extensions scripts do the rest. I copied my Outputs windows below so you can see exactly what happens.
Next you just have to (1) Add the Web Part (2) put your settings for Width, Height, and URL, and GO!