Download Visual Studio 2008 Extensions for Windows SharePoint Services (requires Windows SharePoint Services 3.0 to be installed first)

You might want to check out this post if you want to install WSS on Vista.

Sample Code
   1: using System;
   2: using System.Runtime.InteropServices;
   3: using System.Web.UI;
   4: using System.Web.UI.WebControls;
   5: using System.Web.UI.WebControls.WebParts;
   6: using System.Xml.Serialization;
   7:  
   8: using Microsoft.SharePoint;
   9: using Microsoft.SharePoint.WebControls;
  10: using Microsoft.SharePoint.WebPartPages;
  11:  
  12: namespace WebPart1
  13: {
  14:     [Guid("f40e66da-5c46-4f9e-b146-3437bacf10a1")]
  15:     [ToolboxData("<{0}:CustomPropertyWebPart runat=server></{0}:CustomPropertyWebPart>"),
  16:         XmlRoot(Namespace = "WebPart1")]
  17:     public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
  18:     {
  19:         const string c_MyStringDefault = "Sample String";
  20:         const bool c_MyBoolDefault = false;
  21:         const int c_MyIntDefault = 20;
  22:         const float c_MyFloatDefault = 33.33f;
  23:         public enum myFarmEnum
  24:         {
  25:             barn=0,
  26:             tractor,
  27:             hay,
  28:             pitchfork
  29:         };
  30:         protected myFarmEnum _myEnum;
  31:  
  32:         // Private variables
  33:         private string _myString;
  34:         private bool _myBool;
  35:         private int _myInt;
  36:         private float _myFloat;
  37:         private System.DateTime _myDateTime;
  38:         private System.Drawing.KnownColor _myColor =
  39:             System.Drawing.KnownColor.Red;
  40:  
  41:         // Constructor
  42:         public WebPart1()
  43:         {
  44:             // Initialize private variables.
  45:             _myString = c_MyStringDefault;
  46:             _myBool = c_MyBoolDefault;
  47:             _myInt = c_MyIntDefault;
  48:             _myFloat = c_MyFloatDefault;
  49:             _myEnum = myFarmEnum.hay;
  50:             _myDateTime = System.DateTime.Now;
  51:         }
  52:  
  53:         // Creates a custom property that is a string.
  54:         // This property will be displayed as a text box in the
  55:         // property pane.
  56:  
  57:         // Create a custom category in the property sheet.
  58:         [SPWebCategoryName("Custom Properties")]
  59:         // Assign the default value.
  60:         //[DefaultValue(c_MyStringDefault)]
  61:         // Property is available in both Personalization
  62:         // and Customization mode.
  63:         [Personalizable(PersonalizationScope.User)]
  64:         [WebPartStorage(Storage.Personal)]
  65:         // The caption that appears in the property sheet.
  66:         [FriendlyNameAttribute("Custom String")]
  67:         // The tool tip that appears when pausing the mouse pointer over
  68:         // the friendly name in the property pane.
  69:         [WebDescription("Type a string value.")]
  70:         // Display the property in the property pane.
  71:         [WebBrowsable(true)]
  72:         [XmlElement(ElementName="MyString")]
  73:         // The accessor for this property.
  74:         public string MyString
  75:         {
  76:             get
  77:             {
  78:                 return _myString;
  79:             }
  80:             set
  81:             {
  82:                 _myString = value;
  83:             }
  84:         }
  85:  
  86:         // Creates a custom property that is a Boolean value.
  87:         // This property will display as a check box in the
  88:         // property pane.
  89:  
  90:         [SPWebCategoryName("Custom Properties")]
  91:         //[DefaultValue(c_MyBoolDefault)]
  92:         [WebPartStorage(Storage.Personal)]
  93:         [Personalizable(PersonalizationScope.User)]
  94:         [FriendlyNameAttribute("Custom Boolean")]
  95:         [WebDescription("Select to set value to True.")]
  96:         [WebBrowsable(true)]
  97:         [XmlElement(ElementName="MyBoolean")]
  98:         // The accessor for this property.
  99:         public bool MyBool
 100:         {
 101:             get
 102:             {
 103:                 return _myBool;
 104:             }
 105:             set
 106:             {
 107:                 _myBool = value;
 108:             }
 109:         }
 110:  
 111:         // Creates a custom property that is an integer.
 112:         // This property will display as a text box in the
 113:         // property pane.
 114:         [SPWebCategoryName("Custom Properties")]
 115:         //[DefaultValue(c_MyIntDefault)]
 116:         [WebPartStorage(Storage.Personal)]
 117:         [Personalizable(PersonalizationScope.User)]
 118:         [FriendlyNameAttribute("Custom Integer")]
 119:         [WebDescription("Type an integer value.") ]
 120:         [WebBrowsable(true)]
 121:         [XmlElement(ElementName="MyInt")]
 122:         public int MyInt
 123:         {
 124:             get
 125:             {
 126:                 return _myInt;
 127:             }
 128:             set
 129:             {
 130:                 _myInt = value;
 131:             }
 132:         }
 133:  
 134:         // Creates a custom property that is a float.
 135:         // This property will display as a text box in the
 136:         // property pane.
 137:         [SPWebCategoryName("Custom Properties")]
 138:         //[DefaultValue(c_MyFloatDefault)]
 139:         [Personalizable(PersonalizationScope.User)]
 140:         [WebPartStorage(Storage.Personal)]
 141:         [FriendlyNameAttribute("Custom Float")]
 142:         [WebDescription("Type a floating point value.") ]
 143:         [WebBrowsable(true)]
 144:         [XmlElement(ElementName="MyFloat")]
 145:         public float MyFloat
 146:         {
 147:             get
 148:             {
 149:                 return _myFloat;
 150:             }
 151:             set
 152:             {
 153:                 _myFloat = value;
 154:             }
 155:         }
 156:  
 157:         // Creates a custom property that is a System.DateTime.
 158:         // This property will display as a text box in the
 159:         // property pane.
 160:         [SPWebCategoryName("Custom Properties")]
 161:         [Personalizable(PersonalizationScope.User)]
 162:         [WebPartStorage(Storage.Personal)]
 163:         [FriendlyNameAttribute("Custom Date Time")]
 164:         [WebDescription("Type a DateTime value.")]
 165:         [WebBrowsable(true)]
 166:         [XmlElement(typeof(System.DateTime))]
 167:         public System.DateTime MyDateTime
 168:         {
 169:             get
 170:             {
 171:                 return _myDateTime;
 172:             }
 173:             set
 174:             {
 175:                 _myDateTime = value;
 176:             }
 177:         }
 178:  
 179:         public bool ShouldSerializeMyDateTime()
 180:         {
 181:             return true;
 182:         }
 183:  
 184:         // Creates a custom property that is an enum.
 185:         // This property will be displayed as a drop-down list in the
 186:         // property pane.
 187:         [SPWebCategoryName("Custom Properties")]
 188:         //[DefaultValue(myFarmEnum.hay)]
 189:         [Personalizable(PersonalizationScope.User)]
 190:         [WebPartStorage(Storage.Personal)]
 191:         [FriendlyName("Custom Enum")]
 192:         [WebDescription("Select a value from the dropdown list.")]
 193:         [WebBrowsable(true)]
 194:         public myFarmEnum MyEnum
 195:         {
 196:             get
 197:             {
 198:                 return _myEnum;
 199:             }
 200:             set
 201:             {
 202:                 _myEnum = value;
 203:             }
 204:         }
 205:  
 206:         // Creates a property that is a known system color.
 207:         // This property will be displayed as a drop-down list in the
 208:         // property pane.
 209:         [SPWebCategoryName("Custom Properties")]
 210:         [Personalizable(PersonalizationScope.User)]
 211:         [WebPartStorage(Storage.Personal)]
 212:         [FriendlyNameAttribute("Custom Color")]
 213:         [WebDescription("Select a color from the dropdown list.")]
 214:         [WebBrowsable(true)]
 215:         [XmlElement(typeof(System.Drawing.KnownColor))]
 216:         public System.Drawing.KnownColor MyColor
 217:         {
 218:             get
 219:             {
 220:                 return _myColor;
 221:             }
 222:             set
 223:             {
 224:                 _myColor = value;
 225:             }
 226:         }
 227:  
 228:         public bool ShouldSerializeMyColor()
 229:         {
 230:             return true;
 231:         }
 232:          /// <summary>
 233:         /// Gets the custom tool parts for this Web Part by
 234:         /// overriding the GetToolParts method of the WebPart
 235:         /// base class. You must implement custom tool parts in a
 236:         /// separate class that derives from the
 237:         /// Microsoft.SharePoint.WebPartPages.ToolPart.
 238:         /// </summary>
 239:         /// <returns>
 240:         /// An array of references to ToolPart objects.
 241:         /// </returns>
 242:         // public override ToolPart[] GetToolParts()
 243:         // {
 244:         //    ToolPart[] toolparts = new ToolPart[2];
 245:         //    WebPartToolPart wptp = new WebPartToolPart();
 246:         //    CustomPropertyToolPart custom = new CustomPropertyToolPart();
 247:         //    toolparts[0] = custom;
 248:         //    toolparts[1] = wptp;
 249:         //    return toolparts;
 250:         // }
 251:         /// <summary>
 252:         /// Render this Web Part to the output parameter specified.
 253:         /// </summary>
 254:         /// <param name="output">
 255:         /// The HTML writer to write out to
 256:         /// </param>
 257:         protected override void Render(HtmlTextWriter output)
 258:         {
 259:             // Write stored property values to the Web Part.
 260:             output.Write("<b>Stored Property Values</b>");
 261:             output.Write("<br><b>String: </b>" +
 262:                 this.MyString);
 263:             output.Write("<br><b>Boolean: </b>" +
 264:                 this.MyBool.ToString());
 265:             output.Write("<br><b>Int: </b>" +
 266:                 this.MyInt.ToString());
 267:             output.Write("<br><b>Float: </b>" +
 268:                 this.MyFloat.ToString());
 269:             output.Write("<br><b>DateTime: </b>" +
 270:                 this.MyDateTime.ToString());
 271:             output.Write("<br><b>Enum: </b>" +
 272:                 this.MyEnum.ToString());
 273:             output.Write("<br><b>Color Enum: </b>" +
 274:                 this.MyColor.ToString());
 275:  
 276:         }
 277:     }
 278: }

Sample Project : WebPart1.zip

For additional SharePoint development resources, navigate to http://www.mssharepointdeveloper.com/

Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!