Disable Chrome in C# SharePoint Webparts

I continue to create a lot of custom webparts for SharePoint 2010.  I found a better way to automatically disable Chrome in your c# webpart class.

public override PartChromeType ChromeType
{
     get { return PartChromeType.None; }
     set { base.ChromeType = PartChromeType.None; }
}

I started using this method because in my advanced webparts where I use and EditorPart to handle webpart options; I hide all the other webpart options. To hide the default webpart options I use the following code.

base.Parent.Controls[2].Visible = false;

This is an update of an earlier post.

New WP Site Launched

The new WordPress site is finally launched. After a period of trying to keep the in house content management system, reedWrite, on par with WordPress I finally decided to let it go and fully develop sites on WordPress. With the upcoming release of WordPress 3.0 custom content type posts will be part of the core. And not to mention all the other great features already a part of WordPress. I plan on deploying some WordPress plugins to help make WordPress the best CMS on the web.

I will be supporting current implementations of reedWrite but have halted production on the beta release.

Fisher–Yates Shuffle of SPListCollection in C#

I like working with c# when not with PHP as it helps me learn deeper ways to do things. Also it constantly makes me grateful for PHP where the following is as easy as shuffle($numbers); in PHP.

C#

public static int[] shuffle(int[] array)
{
Random rng = new Random();  // System.Random
// n is the number of items remaining to be shuffled.
for (int n = array.Length; n > 1; n--)
{
// Pick a random element to swap with the nth element.
int k = rng.Next(n);  // 0 <= k <= n-1 (0-based array)
// Swap array elements.
int tmp = array[k];
array[k] = array[n - 1];
array[n - 1] = tmp;
}
return array;
}

Disable Chrome in C# Sharepoint 2007 Webparts

This post was updated here.

I create a lot of custom webparts for SharePoint 2007. One slightly annoying thing is remembering to turn of the Chrome when adding webparts to pages. It can also be a problem when your advanced clients who are adding webparts forget to to disable the Chrome.

In your c# webpart class slap in the following code to automatically disable Chrome. You can’t even select anything other than Chrome so be careful.

public override PartChromeType ChromeType
{
get {
return base.ChromeType;
}
set {
base.ChromeType = PartChromeType.None;
}
}

PHP Range

Ever need an array of the alphabet or an array of sequential numbers.

The range() function in PHP does just that.

<?php
foreach(range('a', 'z') as $letter) {
echo $letter;
}
?>

This function will also work with numbers. This will print all the numbers from 1 to 12.

<?php
foreach(range(0, 12) as $number) {
echo $number;
}
?>

Also you can add a step parameter to the third argument.

<?php
foreach(range(0, 50, 10) as $number) {
echo $number;
}
?>

0, 10, 20, 30, 40, 50

I was wondering of there was an smarter way to print the whole alphabet in PHP than just creating an array containing all off the letters by my self.

I present to you, the range() function.

<?php
foreach(range('a', 'z') as $letter) {
    echo $letter;
}
?>

This function will also work with numbers. This will print all the numbers from 1 to 12.

<?php
foreach(range(0, 12) as $number) {
    echo $number;
}
?>

And if you are smart, and run PHP 5, you can even print every tenth number (0,10,20,30…)

<?php
foreach(range(0, 100, 10) as $number) {
    echo $number;
}
?>