Rating: No reviews yet
Downloads: 5408
Released: Feb 20, 2008
Updated: Aug 6, 2008 by sasa
Dev status: -not yet defined by owner-

Recommended Download

application, 8K, uploaded Feb 20, 2008 - 2612 downloads

Other Available Downloads

application, 42K, uploaded Aug 6, 2008 - 1248 downloads
Source Code
source code, 2K, uploaded Feb 20, 2008 - 1548 downloads

Release Notes

First release of ASPNETLibrary.SharePoint.WebParts assembly includes BaseSkinnedWebPart and swpgen.exe console application.

Why base Web Part?

When I started working with Web Parts the first thing that I really missed was a possibility to work with Web Parts the way I worked with ASP.NET web pages and web user controls. In other words, I missed the ability to separate design/layout of Web Part from the "code behind" or business logic. Beside the fact that design is not separated from code behind I really didn't like the fact that I had to spend a lot of time writing everything manually.

The solution

Some time ago I read a great article made by Michiel Van Otegem about skinned controls ( Based on his idea and based on functionality of his SkinnedPart I made BaseSkinnedWebPart which is slightly improved Michiel's control. Beside that I created a console application that generates Web Parts based on already made skins.
Another advange of using this control is the fact you can create multiple skins (ASCX) controls and choose different look for your Web Parts at runtime.

Using BaseSkinnedWebPart and swpgen.exe (generator tool) developers can work with web parts almost the same way they work with web pages and web user controls. Base idea is as follows (more details explanation will follow below):
  1. Create an ASCX control without code behind (just ASCX file with ASP.NET controls and other HTML)
  2. Use swpgen.exe to generate class that inherits from BaseSkinnedWebPart and uses previously made ASCX control (skin)
  3. Add generated classes to a Web Parts project and add additional functionality the same way you would work with a regular web page.

Usage guidelines

Here are more detailed steps on how to use generator and base class:
  1. Create an ASCX control without the code behind. Check "Samples\SampleWebPart.ascx" from for an example of a skin. NB: you can always modify the skin later by adding new controls or modifying existing controls.
  2. Use swpgen.exe to generate class that inherits from BaseSkinnedWebPart and uses previously made ASCX control (skin). You can type swpgen to get the usage guidelines but in most cases you would use it like this: swpgen /source:MyWebPart.ascx /namespace:MyCompany.MyProject.WebParts. If executed like that tool will generate two files: MyWebPart.cs and MyWebPart.generated.cs.
  3. Add two generated files to your Web Parts project and start modifying the one without ".generated.cs" in its name. The file that ends with ".generated.cs" should not be modified because you may decide to modify skin later and to regenerate the classes (in that case you would replace only the ".generated.cs" file and leave the other one where you make your own changes.
  4. Add a reference to ASPNETLibrary.SharePoint.WebParts.dll assembly to your Web Parts project
  5. Start modifying the first generated file. You can check "BaseSkinnedWebPartSample2.cs" sample from "aspnetlibrary\Development\Src\ASPNETLibrary.SharePoint.WebParts\Samples\BaseSkinnedWebPartSamples\BaseSkinnedWebPartSamples\"
  6. After you finish with implementation and deploy Web Part to MOSS, create a document library called Themes and create a folder in that document library for each theme you want to have. NB: by default, skinned web part will try to find Themes\default\SKINNAME.ASCX file;
  7. Upload skins (ASCX files) to the right folders under the Themes document library
  8. Add your Web Part to a web page in MOSS and select "Modify Shared Web Part" option for the Web Part
  9. Go to "Skinned Web Part Skin Settings" section select a theme folder and then select your prefered skin. Click on OK and your Web Part will be rendered with the selected ASCX control.

More detailed article with details of implementation and usage will follow soon.

Future plans

My plan is to make a VisualStudio addin that will allow generation of skinned Web Parts from IDE.

Reviews for this release

No reviews yet for this release.