First Apologies, I pulled the code from the previous articles as I wanted to ensure that it at least compiled, so I spent some time creating a full working version which I’m publishing here.

So. Web Part Skins.  This is different to just altering the CSS it combines having a base class for your custom webparts that modifies the render mechanism.  Luckily there are two handy methods that MS provide in the API that give you the HTML that surrounds the Web Part (GetDesignTimeHeader, GetDesignTimeFooter), from that you can regex it till your hearts content.

You could extend this further by using the techniques described in http://blog.spsclerics.com/archive/2005/07/11/5421.aspx A rounded Corner header for webPart.

One drawback of this is that it is only for your own custom web parts as you need to inherit from WebPartBase (or just code it in directly).  It is possible to replace the MS Content Editor in Sharepoint by editing the DWP files in the Area Template Folders and point it at a new one you create yourself.  I have done this on a Portal (I also removed the HTML edit button in mine so no-one goes putting Jscript directly in the editor part, you could also run a HTML validator routine to ensure no nasty tags go in your portal).  Because the content editor part is now mine and not MS I can apply this skin all over the place, and the Content part is the most widely used. *N.B. Editing dwp in templates – This falls under not supported so be warned.

You can’t do it for any of the list parts which is a shame unless you hard code it in the CSS for all parts (like the example from spsclerics).

Here is the code, in this version I used a SNK file (I uploaded it) I used a resx file for resources, the WebPartBase project properties have my namespace in them so go take a look (as the resx relates to this namespace here). I GAC my WebPartBase. 

You should use your own SNK file not mine (its just a dummy one not really mine)
The CSS should be copied into the Styles folder and the Portal should reference it by
altering the site settings (or hack them into ows.cs)

dummy_snk.zip (.7 KB)
InheritingPart.zip (4.63 KB)
bjam.zip (.63 KB)
WebPartBase1.zip (9.77 KB)

Advertisements