Thursday, September 23, 2010

Latest ASP.NET Vulnerability Fix For SharePoint

The latest discovered ASP.Net vulnerability affects SharePoint 2007 & 2010.  The SharePoint Team's blog has the instructions for the temporary fix here:

Wednesday, September 22, 2010

Turn on versioning on a site's Document Libraries.

We had a lot of sites that needed to have versioning turned on, here's a simple console app I wrote to do this, you just pass the url of the web as an argument:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Mirant.Utilities.SiteVersioningActivator
    class Program
        static void Main(string[] args)
            if (args.Length != 1)
                throw new Exception("URL of the site is required as a parameter");

            string webUrl = args[0];

            using (SPSite site = new SPSite(webUrl))
                using (SPWeb web = site.OpenWeb())

                    foreach (SPDocumentLibrary docLib in web.GetListsOfType(SPBaseType.DocumentLibrary))
                        docLib.EnableVersioning = true;
                        docLib.MajorVersionLimit = 5;

Tuesday, April 27, 2010

Getting a usable SPItem URL to a display form

This is definitely from the "I can't believe I hadn't blogged this already department".

When you try to use the SPListItem.Url property you wind up getting a url that's relative to the site (even though it starts with a '/').

I've written this method that will return a list item url and takes into account the fact that the urls differ when they're lists or document libraries:

private string GetItemUrl(SPListItem listItem)
            string result;

            string itemUrlTemp = listItem.Url.Replace("Lists/", "");
            string siteRelativeListUrl = itemUrlTemp.Substring(0, itemUrlTemp.IndexOf('/'));

            if (listItem.ListItems.List.BaseTemplate == SPListTemplateType.DocumentLibrary)
                result = SPEncode.UrlEncodeAsUrl(String.Format("{0}/{1}/Forms/Dispform.aspx?ID={2}", listItem.ListItems.List.ParentWeb.Url, siteRelativeListUrl, listItem.ID));
                result = SPEncode.UrlEncodeAsUrl(String.Format("{0}/Lists/{1}/Dispform.aspx?ID={2}", listItem.ListItems.List.ParentWeb.Url, siteRelativeListUrl, listItem.ID));

            return result;


Monday, April 26, 2010

Setting up a SharePoint 2010 Developer VM using VirtualBox

I spent a few hours this weekend creating a SharePoint 2010 Developer environment using the RTM.

For now, I'm approaching my dev build the same way I had my MOSS 2007 VM set up - a standalone MOSS install with Visual Studio installed.

Because I wanted to use a 64bit guest OS (64bit Server 2008), I decided to use VirtualBox as my VM solution, if you want to use VirtualBox, you can get it here. I should note that when I set up my VirtualBox VM I gave it 20GB of hard drive space which was not enough so I had to expand the drive (described later orange text). I'd suggest going to 40 or more if you can because Windows,SP2010, SQL, and Visual Studio take up about 18GB (and setting it up right the first time will save you from having to do this.

Once I had Server 2008 installed on a VirtualBox VM I downloaded the RTM version of SharePoint from MSDN.

I then attached the SharePoint 2010 .iso file to my VM, opened the mounted SharePoint 2010 image and ran the Prerequisite installer (I got an error as autorun tried to run).

After the prerequisite installation finished, I ran the setup, entered my product key, and chose to do a Standalone install. (I might do a Farm install so that I can use SQL Server as my backend, but you need to use Domain Accounts if you want to do this and I haven't set up a developer domain yet).

I did run into one hiccup, apparently during the installation I got a BSOD (though since I walked away during the install I didn't see the details). Once the server came back up and I realized what had happened, I reran the installer and the installation finished successfully, however, the Configuration Wizard wouldn't run (I got a 'failed to start the database service MSSQL$SharePoint' error). After going to Control Panel, then to the Uninstall Programs screen, I chose SharePoint 2010 (this wont show up unless you finish the install after the Blue Screen) and then chose 'Change', and selected 'Repair'. After the repair, SharePoint asked for a reboot, so I rebooted.

Once the server came back up I was able to run the Configuration Wizard without the 'failed to start...' issue. The configuration wizard ran through its thing and finished successfully. To verify a successful install I pulled up Central Admin to ensure that SharePoint 2010 was indeed installed successfully. After being prompted for credentials, Central Admin came up.

*Next, I had to expand my Virtual Box VDI file.  This process is documented here.

After that I tried to install Visual Studio 2010.   I got through all the installer wizard screens but got an error upon the actual install, apparently the VS 2010 iso doesn't mount well in Virtual Box.   So I took my VM's browser to msdn and downloaded the VS 2010 web installer.   I ran the web installer and went to bed.   I later returned to see that after .NET Framework 4's installation I needed to reboot.   I rebooted the VM then reran the web installer and it picked up where I left off.

Next I moved on to SharePoint Designer, based on my experience with VS 2010 not installing from a mounted drive in VirtualBox, I chose to download the Designer 2010 code directly in the VM.  I couldn't find it on MSDN, so I downloaded it here.  The installation went smoothly without any issues.

Sunday, April 25, 2010

Expanding a VirtualBox VDI file for Server 2008 x64 R2

I use virtual box as my SharePoint VM host because I want to be able to run 64bit Server 2008 R2 on my Windows 7 host machine.   When I first installed SharePoint 2010, the VDI (Virtual Disk for VirtualBox) I created was too small, so I had to expand it.   This is a bit of a challenge, but by doing some research I figured out how to do it.

The process involves creating a new, larger disk and copying the original boot and main partitions to the newer disk.   This can be done with gparted.  and the steps to do so are well documented here

However there are a few more steps you'll need to follow because you are using 64bit Server 2008 R2:
  • After you've followed the above instructions, mount the newer larger drive as the Primary Master and mount the Server 2008 R2 ISO.
  • Boot to the ISO (hitting any key when prompted)
  • Choose your language then on the next screen select repair
  • Select the partition and click ok
  • Choose the command line option
  • Switch to your c: drive
  • Type bootrec.exe /fixboot
  • Type bootrec.exe /rebuildbcd and after it runs successfully type A and hit enter to add the entry to the BCD store
  • Type exit and reboot the machine.
  • The machine should load, but kind of slowly, and then scandisk will run (allow it to run to completion), then windows should come back up.

Monday, March 15, 2010

Change Default Search Scope of your Search Results Page

This, surprisingly, took a lot of digging to come up with, but the solution is simple.

1. Go to your search results page
2. Click Site Actions > Edit Page
3. On the search Core Results web part choose 'Modify Shared Web Part'
4. Expand the Miscellaneous section.
5. Type your scope name in the 'Scope' box, then click apply.
6. Test your Search

Wednesday, January 6, 2010

Using Milkbox with SharePoint

Recently we needed to integrate Milkbox (Lightbox that supports Flash and other things) to our SharePoint-based Intranet Site.

In order to do this you need to do the following to your master page.

  1. Download the Milkbox Code. Depending on how you plan to implement this solution you can store the files in a number of places, either in a doc library or on the file system in the 12 hive. In this example I created an STSDEV solution and added the downloaded files into the solution so they would deploy to the TEMPLATE/LAYOUTS directory in the 12 hive. If you choose to save it to another location, be sure to update your references from the '_layouts/...' references I gave to the .js and .css files.

  2. Ensure the following DOCTYPE declaration is at the top of your masterpage:

    <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>

  3. Ensure the following assembly registration is in the top of your master page:

    <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

  4. In the <head> section of your master page add the following (Also, pay attention that the version numbers match up with the most current version you've downloaded):

    <PublishingWebControls:EditModePanel PageDisplayMode="Display" runat=server id="MilkboxPanel">
    <!--Lightbox -->
    <script type="text/javascript" src="/_layouts/Lightbox/milkbox-2.3.2/js/mootools-1.2.3-core-yc.js"></script>\>
    <script type="text/javascript" src="/_layouts/Lightbox/milkbox-2.3.2/js/mootools-"></script>
    <script type="text/javascript" src="/_layouts/Lightbox/milkbox-2.3.2/js/milkbox.js"></script>
    <style type="text/css">
    @import url(/_layouts/Lightbox/milkbox-2.3.2/css/milkbox/milkbox.css);
    <!--End Lightbox-->

    *Notice the Edit Mode panel wrapping the <style> and <script> tags. This is to prevent a javascript error that appears when the page is in edit mode and you try to edit a text field. This fix was proposed by Steve Mann of RDA, thanks for the help!

  5. In your page content area, ensure that your links include the milkbox 'rel' attribute:

    <a href="img/01b.jpg" rel="milkbox" title="Caption goes here...">image #1</a>

After this setup, you should be able to use Milkbox as it is documented on the page