Krichie – That SharePoint Guy

January 31, 2007

Welcome Back Mr. Prather!

Filed under: General — Keith Richie @ 5:54 am

Maurice just got back from a 2.5 month vacation :)

I couldn’t help but think of welcoming him back if I just didn’t do it in style :)

For those not old enough to remember Welcome Back Kotter, sorry :)

Welcome back

Your dreams were your ticket out.

Welcome back

To that same old place that you laughed about.

Well the IPs have all changed since you hung around,

But those dreams have remained and they’re turned around

Who’d have thought they’d lead ya (Who’d have thought they’d lead ya)

Back here where we need ya (Here where we need ya)

Yeah we tease him alot, cause his power’s always out.

Welcome back.

Welcome back, welcome back, welcome back!

Oh Oh Oh Mr. Kotter!! (I mean Mr. Prather!)

Welcome back buddy :)

 - Keith

January 30, 2007

Deep thoughts by Supermom

Filed under: General — Keith Richie @ 11:22 pm

My wife just posted this blog entry on her MySpace.  The key thing I’d like to bring out about this post, is the final paragraph in which she notes:

“Giving to others does not have to be grand or expensive. Sometimes it is the most simple things that make the biggest difference. No I can not change the world, just my corner and you can help in your corner. World issues will always be there, we can not change that. We can however put a smile on someones face.

I would encourage you to read the entire post when you have a moment.

Now, I’m going to take a small break, walk out of the office and give her a big hug :)

 - Keith

SPWeb.Configuration, bug?

Filed under: Development, SharePoint — Keith Richie @ 7:34 am

I ran across this the other day while debugging something and thought I would share.

At first, I thought it was a problem in the site building tool I wrote and was using, but later confirmed this to be a problem even in a subweb created from the SharePoint UI.

What I saw

My test sites were generated from my SPSiteBuilder tool that uses SPWebCollection.Add(“site-relative URL”)

V2 Reference

http://msdn2.microsoft.com/en-us/library/ms980143.aspx

V3 Reference

http://msdn2.microsoft.com/en-us/library/ms411806.aspx

When you use this overloaded version of the Add method, in V2, it sets the sites template to the default STS#0 (Default Team Site), and thus SPWeb.Configuration results in 0.  In V3, it still works the same because you can immediately browse the site and it’s just fine, yet SPWeb.Configuration results in -1.

For example, given the following sample code:


public
static
void InspectWeb(SPWeb web, bool bRecurse)

{


Console.WriteLine(“web.Url: “ + web.Url);


Console.WriteLine(“web.ID: “ + web.ID);


Console.WriteLine(“web.Configuration: “ + web.Configuration);


if (bRecurse)

{


foreach (SPWeb subweb in web.Webs)

{

InspectWeb(subweb, bRecurse);

}

}

}

And the web was opened with by passing the URL to the SPSite Constructor, then calling SPSite.OpenWeb()

If I open the parent web first, and recurse I get the following:

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1

web.ID: 58faab9c-9bb6-46c6-9f99-46a08b5555b0

web.Configuration: 0

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: -1

 

Yet, if I use the same code directly at that web:

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: 0

 

What I found

At first, I thought it was a bug in the SPWebCollection.Add() method. But I just confirmed that you get back the same result when you create a subweb via the UI as well. See below:

 

C:\dev\sometool http://krichiewss3/sites/SPSiteBuilderSite1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1

web.ID: 58faab9c-9bb6-46c6-9f99-46a08b5555b0

web.Configuration: 0

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/SPSiteBuilderSite1_d1_w1

web.ID: 866311ca-c2a0-4d45-941f-ff1551b2954b

web.Configuration: -1

web.Url: http://krichiewss3/sites/SPSiteBuilderSite1/UICreatedWeb

web.ID: 130d7487-aa29-4774-b7db-c0a1e048edef

web.Configuration: -1

 

In the following test, I created the Site Collection and the subweb both in the SharePoint UI without custom code, yet enumerating the sub webs via SPWeb.Webs still produces the same result

C:\dev\sometool http://krichiewss3/sites/UICreatedSite

web.Url: http://krichiewss3/sites/UICreatedSite

web.ID: 907eacbe-f673-4c9a-be28-6c3f29bbf9ee

web.Configuration: 0

web.Url: http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.ID: 97798d22-c3b3-45ea-9bd8-a6b6e9150312

web.Configuration: -1

And if I just open that web directly:

C:\dev\sometool http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.Url: http://krichiewss3/sites/UICreatedSite/UICreatedWeb

web.ID: 97798d22-c3b3-45ea-9bd8-a6b6e9150312

web.Configuration: 0

 

I see no references to this property being neither deprecated nor obsolete. And I’ll need to let the powers that be know about it, just wanted to share with you that this appears to be a problem in WSS/MOSS RTM bits.

Then again, I could be missing something here, but you get two different results for SPWeb.Configuration depending on how you get a reference to the web.

  • Keith Richie

Traversing SharePoint List Folder Hierarchies

Filed under: Development, SharePoint — Keith Richie @ 6:28 am

Windows SharePoint Services 3.0 (WSSv3) and Microsoft Office SharePoint Server 2007 (MOSS2007) now support the ability to create folders within lists. This is quite frankly one of the coolest features in this release of the products (well, aside from all the OTHER coolest featuresJ), but the point is, it also adds a layer of complexity to how you enumerate lists now if you want to traverse a List folder hierarchy the same way you might want to enumerate a Document Library folder hierarchy.

This is something that was giving me a real headache trying to figure out how to do all day long. (Strangely, the solution I came up with I thought about a couple of days ago, I just didn’t want to have to do it this way, nor did I think I would “Have” to do it this way). I searched around, referenced the SDK, searched around more, but still came up blank. After collaborating with a lot of my peers and friends (And for those of you I pinged on this, thanks for your suggestions), I found that the suggestions they were sending me, were paths I already took and found they would not work J But, just after I harassed them, I realized what the solution was J

What I’m going to do first, is provide you a bit of background on what I attempted, and show you why those solutions don’t workJ. Then show you the solution that will work against both Lists and Document Libraries, or any list in generalJ.

Traversing a Document Library (In WSSv2 or WSSv3) was a simple process. Consider the following code if you were enumerating the document libraries using the lists collection of a SPWeb

// Within some method somewhere

foreach(SPList list in web.Lists)

{

if(list.BaseType == SPBaseType.DocumentLibrary)

    {

//Traverse the folder

TraverseFolder(list.RootFolder);

    }

}

TraverseFolder might be implemented something like this:

public
long TraverseFolder(SPFolder folder)

{

// Do something interesting on the folder

// Perhaps sum up the file sizes

long lFolderSize = 0;

try

{

    foreach (SPFile file in folder.Files)

lFolderSize += file.Length;

if (bRecurseFolders)

{

foreach (SPFolder subfolder in folder.SubFolders)

lFolderSize += TraverseFolder(subfolder);

}

}

catch (Exception e)

{


Console.WriteLine(e.Message);

}

return lFolderSize;

}

It would be nice if you could do the same thing with a base SPList, but you can’t J

You may be inclined to start with something like this, the same way I was inclined to do so J

foreach (SPListItem item in list.Items)

{

Console.WriteLine(“List item: “ + item.Name);

Console.WriteLine(“List item type: “ + item.ContentType.Name);

}

// Folders are not counted in list.Items, so we have to look at those seperately.

// But, the Folders collection is just another collection of SPListItems.

foreach (SPListItem item in list.Folders)

{

Console.WriteLine(“List Folder item: “ + item.Name);

Console.WriteLine(“List item type: “ + item.ContentType.Name);

TraverseListItem(item);

}

But there are a couple of problems with this approach

  1. The items returned from via SPListItemCollection at list.Items, returns ALL items over the whole list hierarchy
  2. The items returned from via the SPListItemCollection at list.Folders, returns ALL folders over the whole list hierarchy

So consider a list that was structured this way:

  • Announcements
    • Item 1 in the root of the Announcements list
    • Item 2 in the root of the Announcements list
    • Folder 1 in the root of the Announcements List
      • Item 1 in Folder 1
      • Item 2 in Folder 1
      • Folder 2 under Folder 1
        • Item 1 in Folder 2
        • Item 2 in Folder 2

The enumeration of list.Items above would return the following items:

  • Item 1 in the root of the Announcements list
  • Item 2 in the root of the Announcements list
  • Item 1 in Folder 1
  • Item 2 in Folder 1
  • Item 1 in Folder 2
  • Item 2 in Folder 2

And the enumeration of list.Folders above would return the following items:

  • Folder 1 in the root of the Announcements List
  • Folder 2 under Folder 1

Let’s assume you have not discovered that yet and when you detect that the item is a folder, you try to treat it this way J

You’re TraverseListItem () call may be implemented something like this:

private
static
void TraverseListItem(SPListItem listitem)

{

SPFolder folder = listitem.Folder;

if (folder != null)

{

// This item is a folder, therefore call on contained items recursively.

Console.WriteLine(“Found a folder!!!”);

Console.WriteLine(“Folder: “ + folder.Name);

foreach (SPFile file in folder.Files)

{

// Do something

}

}

}

The problem is that even though the list item is a folder, and you get a valid SPFolder
back from listitem.Folder, but unlike a Document Library, it will have a count of zero.

But hey! There is a listitem.ListItems collection! That would work right?

private
static
void TraverseListItem(SPListItem listitem)

{

SPFolder folder = listitem.Folder;

if (folder != null)

{

// This item is a folder, therefore call on contained items recursively.

Console.WriteLine(“Found a folder!!!”);

Console.WriteLine(“Folder: “ + folder.Name);

foreach (SPListItem item in listitem.ListItems)

{

// Do something

}

}

}

No, that collection returns the base SPListItemCollection from the list itself, just like SPList.Items and this would get you into a never ending loop, as you’d just recurse the same items, over and over, and over, and over, <Hey go away you pesky wabbit!>

Ok, so maybe you rethink it all, and decide to treat the list as a SPDocumentLibrary
and do what you know works. But no, the base type of a List is GenericList, not SPDocumentLibrary, therefore something like this won’t work:

SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Announcements"];

So, just how the heck to you enumerate the folder items in a list when you discover that the item you’re looking at is in fact a folder?

It’s actually very easy, but I would vote it’s a horrible way to have to go about it.

Enter SPQuery:

private
static
void TraverseListFolder(SPFolder folder)

{

// Get the collection of items from this folder

SPQuery qry = new SPQuery();

qry.Folder = folder;

SPWeb web = null;

try

{

web = folder.ParentWeb;

SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);

foreach (SPListItem subitem in ic)

{

Console.WriteLine(“List item: “ + subitem.Name);

Console.WriteLine(“List item type: “ + subitem.ContentType.Name);

if (subitem.Folder != null)

TraverseListFolder(subitem.Folder);

}

}

catch (Exception e)

{

Console.WriteLine(e.Message);

}

finally

{

// Cleanup that nasty web reference.

if (web != null)

web.Dispose();

}

}

Ok so cool, we now have a way to get ONLY the items in a folder within a list at any level without introducing any items that are not in scope.

So, we’ll just use this method, and to traverse the list, but hey, where do you start? Well, fortunately SPList exposes a RootFolder property that gives you a SPFolder object to start with J

So we can write our List traversal Kick off method as such:

private
static
void TraverseList(SPList list)

{

Console.WriteLine(“Traversing list: “ + list.Title);

Console.WriteLine(“Base Type: “ + list.BaseType.ToString());

TraverseListFolder(list.RootFolder);

}

Simply pass in a reference to a list, and away we go. Very compact, and it works regardless if the list being passed in is a Document Library or any kind of list.

Hope this helps!

  • Keith Richie

January 29, 2007

Oh what a difference, a differencing disk makes…or does it?

Filed under: General — Keith Richie @ 7:43 pm

I was really torn on just how big of a difference, using differencing disks in Virtual PC was giving me on saving diskspace, until I spent some time last night with the following tests to see if it was worthwhile for me.

Let me state, your methods for using Differencing disks may be completely different than mine, and in some scenarios, there is big benefit.  These are simply “My” opinions based on how I do “My” virtual machines :) .

First let me start with a post from my peer at Mindsharp, Andrew Connell titled HOWTO: Use Virtual PC’s Differencing Disks to your Advantage.  (Note, Andrew has already stated he needs to do another update on the article, I’m just basing this post on what’s contained in it)

Andrew did a great job of detailing how he uses Differencing Disks to optimize his development environments.  The problem I have with this scenario, is on his second section about defragmenting the second layer base disks. 

What I found, is if you defragment the differencing disk (Because the second layer, or final layer for that matter, “IS” a differencing disk), it actually causes more diskspace to be used. 

Why?

Because the differencing disk is a “Delta” of the layout from the original base disk to the new disk.  If the defragmenter sees that it’s best to move around files in the differencing disk, that were core files from the base disk, the size of the differencing disk is expanded to record the change from the base disk itself.  Therefore if you optimize your differencing disk, you run the chance of completely negating what you set out to do.

To see the difference in results, I performed the following task with some images I already had.  Here was the basic layout:

WIN2003ENT-IIS-SYSPREPPRED-BASE-0.VHD

3,240,762 KB

This was my base disk which I believe the name pretty much denotes what it contained.  It was precompacted, and defragmented before it was SYSPrepped.

From this base disk, I built out my development environment as follows

krichie.dom consists of the following machines (All sizes in KB, and the Initial Size is the size of the differencing disk “After” defragmenting):

KRICHIEDC01

DC and SQL2005 (I placed the SQL databases themselves on a completely different virtual disk, but I’m not including that size here, as it doesn’t come into the overall equation).  This is the initial DC for my krichie.dom forest

Initial Size: 4,322,372

Total With Base: 7,563,134

KRICHIEMOSS

Member server of krichie.dom with MOSS2007 installed on it, as well as Visual Studio 2005 (Yes I even installed MSDN for 2005, I know there are better ways to handle this, but well…I wanted it to be there in case I was disconnected and could not pull up online.  I’m pretty sure that at some point, I will re-configure it to put MSDN on a seperate shared virtual disk, so I can port it around and re-use it…thus reduce the overall size of my virtual disk)

Initial Size: 11,996,053

Total With Base: 15,236,815

KRICHIESPS2003

Member server of krichie.dom with SPS2003 installed on it, as well as Visual Studio 2003 (And yes, MSDN for 2003 on it)

Initial Size: 7,995,332

Total with Base: 11,236,094

Take the initial size of the three differencing disks + the single size of the base disk, and that equates to: 27,554,519.  That’s 27 GIG!.  The Initial Size of the differencing disks became so large because of the defragmenting.  As well, I noticed that precompacting them also increased their size too, again…it’s all because of the delta from the base image.

When I saw this, I realized that I’m not really saving anything from using differencing disks IF I defragment them.  If I didn’t defragment them, then yes, I would be saving tons of space, but the differencing disks would be horribly slow because of fragmentation.

I then took each differencing disk, and merged them with the base into new images, and the result was as follows (Values are the merged sizes):

KRICHIEDC01: 5,371,202

KRICHIEMOSS: 13,143,211

KRICHIESPS2003: 9,160,927

Therefore, with unique non differencing disks, the total size was 27,675,340.  An actual disk space loss of 120,821 (120 MB)

But then, I defraged each disk, precompacted, and compacted and the results were as follows:

KRICHIEDC01: 4,367,437

KRICHIEMOSS: 9,066,696

KRICHIESPS2003: 7,419,702

Afterwards, my total disk space used by the images was 20,853,835, which in the end, saved me 6,700,684, nearly 7 GIG of diskspace.

In conclusion, if you need to fire up quick environments for whatever reason, then yes…using Differencing disks and a base image like this is a dream.  But, in my scenario, the overall disk loss doesn’t help me.  Yes, I’m going to hate rebuilding these things all the time because of activation (I don’t have a Volume License key for Windows Server :) ), but I’ll just live with that for the time being.

I’m probably going to try Invirtus VM Optimizer next as Andrew notes here.  Only $70 for the home office edition.  Don’t know that I’ll rush out to get it right now, but perhaps in the future.

I’ll post a follow up to this, after I give it a whirl.

 - Keith

BSG Season 3 – Episode "Rapture"

Filed under: Battlestar Galactica — Keith Richie @ 7:06 am

Now talk about trying to get my wife caught up on what’s going on in the BSG world now.

She glances from time to time, and asks (Speaking about Sharon) “Ok, I thought she was a cylon”

My response: “She is, but not the same one”

She states and asks: “Yeah, I got that!  I’ve caught that much, but why is she back in uniform?”

My response: “She’s regained trust”

And then, we get Rapture.  

Without spoiling it for anyone directly (FYI, you can always go to www.scifi.com/battlestar and see the synopisis which is a big spoiler if you have not seen the show)…How the heck am I going to explain it all to her now?  Well, I guess she’s just going to have to sit down and watch it all with me :) Starting from the beginning! (Yeah, I’m still working on that :) .  Gotta FIND the time.

But, tonights episode, “Taking a Break…” is just what I’m going to do right now.

- Keith Richie

BSG: Season 3 – Episode "A Measure of Salvation"

Filed under: Battlestar Galactica — Keith Richie @ 6:56 am

 

(Originally posted on 11/11/2006 to my music business blog, moving to my personal blog)

(Excerpt from the episode synopsis on scifi.com)

“…deep in the heart of the Cylon fleet, D’Anna and Caprica Six have turned against Baltar. They believe that he knew about the virus all along and led them to the nebula in order to kill them. To make him confess, they torture him. Wracked with pain, Baltar flees to the comfort of the Six in his mind, who might offer his only hope for salvation.

Back on the Galactica, Lee Adama has a chilling brainstorm: if they maneuver the Galactica within close range of a Cylon resurrection ship and kill their Cylon prisoners, the infected prisoners will then download to new bodies, spreading the virus to the Cylon fleet in the process. The disease will then rage freely throughout Cylon civilization, eventually wiping out the entire race.”

Read the full synopsis here.

 


 

So I’m glad my kido was not around during this episode.  And in fact, the scifi channel did put up a view discretion disclaimer before each scene that was not for younger audiences.

What’s really cool, is my wife (Who really doesn’t like SciFi at all :) :)) is keen on getting caught up on it now, because everytime she glances at it, something peaks her interest, and she’s completely lost :)   She’s interested in watching the series from the start now to get caught up.  In fact, when the SciFi channel did the “The Story So Far” at the kick off of Season 3, she wanted to watch it so she would know what’s going on.  I told her to just watch the series with me, from start till now, and I think she agreed….So …Super cool :) .

I showed her my Christmas list last week :)

- Keith

BSG: Season 3 – Episode "Torn"

Filed under: Battlestar Galactica — Keith Richie @ 6:54 am

(Originally posted on 11/04/2006 to my music business blog, moving to my personal blog)

As usual, this weeks episode goes to show you that you just can’t predict this show :) I LOVE IT!

I’m not going to spoil it for those who haven’t seen it yet, but you can read the synopsis here to get an idea of what’s contained in this episode.  What I will say though, is just when you think you have Adama figured out, BAM!

Throughout the series, I think I have to say that my favorite characters are Adama and Baltar.   Like a small child caught in a lie, and continously caught in a paradox of lies to try and stay out of trouble, James Callis is doing an “Insanely” great job as Baltar :) .

Who are your favorite characters?

- Keith

Santa apparently was watching :) BSG!

Filed under: Battlestar Galactica — Keith Richie @ 6:52 am

(Originally posted on 12/25/2006 to my music business blog, moving to my personal blog)

Yep, apparently Santa was definitely watching.  My Christmas present was in fact Every single classic and new BSG DVDs.  One word……Sweeeeeeeeeeeeeet!!!!  Didn’t get the Music CD’s as I mentioned in my previous post, but I’m not unhappy at all, besides…I said “I can hold off on that”.

I am so pumped!!!!

I’ve actually missed a couple of episodes from this season.  Hero, and the most recent episode: Rapture.   I’ll be buying Hero from the iTunes store, and I think I still have a chance to catch Rapture on Monday night.  Otherwise, I can just wait for the replay…..but I think I’ll spend the few bucks to go ahead and download Hero at least so I can catch it.  Don’t want to miss any possible plotlines that may have been introduced in Hero.

So if Santa (ehem, my wife) is reading….Thanks so much! It was awesome….I hope you enjoyed your gift as well!

P.S.

Big changes coming in my life soon.   Can’t talk about it now, but big, big, big, big.   Been doing an emmense amount of praying, discussions with my wife, etc before we made this decision.  And well, it’s been quite stressful.   It’s all good though.   Trying to really truly take a few days off from even thinking about work for a change, and spending some quality time with my family.  It’s something I don’t do that often, and something I’m learning to do :) .

- Keith Richie

My Christmas List :) BSG All the way baby!

Filed under: Battlestar Galactica — Keith Richie @ 6:50 am

(Originally posted 10/21/2006 on my music business blog, moving to my personal blog)

Ok, so it’s getting close to Christmas time, and usually I wind up buying my own gift, and then no one knows what to get me.  I’m always pretty surprised by what my wife gets me, but this year…I’m going to “Prevent” myself from getting these myself and turn it over to my wife.  So here’s my list :) .


The New Series DVDs

The Original Series DVDs

Music CDs

Of course, I’d also love the CD’s of all the soundtrack music, but I can hold off on that :) .


Thinking of hosting a Frak Party

If you visit the SciFi page regularly, you may have heard about the official Frak Party site.   I was thinking of hosting one, but well…Not sure of the “Exact” kinds of people showing up :)    So I think I will host a Frak Party for my friends and family, then see how it goes.


 - Keith

Older Posts »

Blog at WordPress.com.