Saturday, March 21, 2009

SharePoint Wiki Coding

Another pitfall!
Recently i was faced with a task of retrieving data from a WSS 3.0 wiki page to be used in some WebPart and discovered quite a few interesting things; Unlike other lists/folders a wiki has some special considerations in order to access its content.
An obvious approach was using the SPWeb object to retrieve the list item as;

SPListItem item = web.Folders[""].Files[]

Here the actual contents of the item is the aspx template used by the wiki page.
A wiki like other files has properties and you will need the [Wiki Field] property to access actual page contents to a string variable.

string wikiContent = item.Properties["Wiki Field"].ToString();

and you got it.

Saturday, March 14, 2009

Div CSS styles

hello designers,
recently had a task which could not suffice with old traditional tables(obsolete)
and had to ditch them for divisions. to make the outlook similar to how a table appeared before requires much use of css styles; a couple of them that were of use;

float:left /* to make two divs appear adjacent to each other(no break) */

position:relative/absolute /* can be used to set div position, handy for div shadows */

filter:alpha(opacity=60); /* transparent div in IE */

-moz-opacity: 0.6; /* transparent div for Netscape earlier versions */

opacity: 0.6; /* transparent div for mozilla and other gecko browsers */

to be sure use all in your css;

be careful with nested divs as styles can be inherited if not set inline for inner divs.

complete reference at www.w3schools.com.

Adding custom properties to webparts

Another handy tip for beginners; ever seen those properties that show up in the toolpane when u want to edit webpart? there is much more that can be added to suit your customization needs.
the general format of c# properties consists of a get and set method for the required value

if u add the following piece of code to the existing you shd get what u want;

[Personalizable(PersonalizationScope.Shared)] //enable personal views

[WebBrowsable(true)]

[System.ComponentModel.Category("My Properties")] /*create category for new property, will default to miscellaneous if undefined */

[WebDisplayName("Another Property")]



private string _anotherProperty;

public string AnotherProperty

{

get { return _anotherProperty; }

set { _anotherProperty = value; }

}

watch out for differences between sharepoint and asp.net webparts

Good luck!