Tuesday, November 24, 2009

SharePoint 2010 - virtual vs non virtual

This has been a very bad week - since the Beta of SharePoint 2010 came out I have been trying to install it and set up a demo environment for developers on my laptop - without much success. Since 2010 requires 64 bit, this ruled out using VPC, and since I don't like using 2008 as the host on my laptop, this meant I had two choices: virtualize with a non-MS solution that allows 64bit clients (virtualbox by sun or vmware) or install sharepoint directly on my windows 7 host - which means I would have Beta software running on my production laptop.

I chose to try virtualbox - and failed twice. First I installed windows 2008r2, and during my presentation to the user group last week it was a disaster - the site kept crashing with unknown error, nothing in the logs and nothing working.

Then I installed a fresh install of windows 2008 with all service packs in the virtual environment - and again installed sharepoint. Again - same symptoms - the site crashes and works SLOWLY.

Finally today I gave up and installed the entire 2010 beta system on my laptop itself - on the windows 7. Apart from the fact that I had to download and install the prerequisites manually (on the server it did it automatically for me) and apart from the fact that I didn't follow the instructions very well (I used 7-zip to extract the .exe file so I can change the config.xml file - which put all files in the one folder - losing the hierarchy. it turns out this gives a "wrong language" error (I forget the exact syntax)) the installation went quickly and easily - so now I have a stand alone windows 7 with sharepoint 2010 and office 2010 and VS2010.

I will keep updating when I have time to play with all of the above...

Modified date stopped working...

So here is the scenario - I had a piece of code in a feature that changed the title of the built-in site column "Date Modified" to...well..."Date Modified". As you can see, the code looks a bit useless, but someone thought it would be useful, so there it was. Next thing I know, the date modified field stopped working in out of the box document libraries. You would edit a document or its properties and the modification date would be the same as the creation date. This would even show in the version history...

Solution - I had to write a small piece of code that would set the SchemaXml property of the site column to the default. It turns out that if you change the field using code (like SPField.Title="Date Modified"; SPField.Update()) then sharepoint removes some very important tags from the schemaxml property of the field - which causes it to break. To fix I just copied over the SchemaXml property from a site column in a brand new site that was not damaged.

Code sample:

try

{

using (SPSite site = new SPSite(txtSite.Text))

{

using (SPWeb web = site.OpenWeb())

{

SPField field = web.Fields.GetField(txtField.Text);

if (field != null)

{

field.SchemaXml = txtSchema.Text;

field.Update(chkUpdateLists.Checked);

MessageBox.Show("Operation completed successfuly");

}

else

{

MessageBox.Show("Field '" + txtField.Text + "' could not be found in the site columns in" + Environment.NewLine+ "'" + txtSite.Text + "'");

}

}

} } catch (Exception ex)

{MessageBox.Show("An error has occured : " + Environment.NewLine + ex.Message);}

Sample schema: <Field ID="{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}" ColName="tp_Modified" RowOrdinal="0" ReadOnly="TRUE" Type="DateTime" Name="Modified" DisplayName="Date Modified" StorageTZ="TRUE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="Modified" FromBaseType="TRUE"/>

Thursday, November 12, 2009

Event handlers in SharePoint 2010

This is too cool...so many more options - take a look at the visual studio 2010 wizard for creating an event handler - it is more than just list items...

I really like the web events - these will be very useful and will allow creating complex solutions without site definitions.

As soon as the beta is out I will write some samples!