SharePoint


13
Dec 09

Quickly searching through a SharePoint List

Background

The project I’m currently working on involves searching through a lot of data as quickly as possible.

There are documents around the Internet that detail the fastest returns for querying a SharePoint list, aside from SQL queries which aren’t supported, the next best way is SPQuery.

1
2
3
4
SPQuery query = new SPQuery();
 
query.Query = BuildQuery();
SPListItemCollection items = list.GetItems(query);

The BuildQuery() method is a place-holder for another project I’m working. The intention will be able to create CAML queries on the fly. I’ve done this for the current project but it’s not really ready to talk about here.


12
Dec 09

Programmatically set the Approval Status of a SharePoint ListItem

Background

I’m working on a project at the moment where the approval of a list item needs to be by a specific person based on the content of the item. Normally this would be a great opportunity to use some Workflow but for other reasons this was decided against.

This particular project is involving a lot of web service work due to the Infopath component, to this end it seemed prudent to use the Web Service to perform the approval action.

Approval Status

The approval status of List Item is held in the ModerationInformation property of the SPListItem object.

1
2
3
4
5
6
7
8
using (SPWeb web = listItem.Web())
{
      bool allowUpdates = web.AllowUnsafeUpdates;
      web.AllowUnsafeUpdates = true;
      listItem.ModerationInformation.Status = SPModerationStatusType.Approved;
      listItem.Update();
      web.AllowUnsafeUpdates = allowUpdates;
}

So updating the Approval is actually very easy. The options for SPModerationStatusType can be found on the following MSDN page for SPModerationStatusType.


10
Dec 09

Web Parts and Workflows

In the coming weeks we will be releasing our new site, Web Parts and Workflow. As an extension of the services provided by Orcon Services Limited, this new site will make high quality off the shelf web parts available for purchase.


30
Nov 09

SharePoint 2010 Beta (and a bit about VHD boot)

Last week SharePoint 2010 Beta was released to the public, you can register for a copy here.

As a developer I am keen to get involved with learning the new features that available as quickly as possible. I’m very pleased to see that Microsoft have allowed this version to be installed on Windows 7 or Vista (both need to be x64).

Another great feature to have come out of Microsoft with Windows 7 is the ability to boot from a Virtual Hard Disk. I’ve set up a Windows 7  (x64) environment on a virtual disk and installed this new beta to fully review it.

Here are the summary steps to installing Windows 7 on a VHD;

  • 1. Boot from the Windows 7 DVD
  • 2. When setup has started, press Shift and F10 to access the command line
  • 3. You now need to run DiskPart to create a virtual hard disk
1
2
3
4
diskpart
create vdisk file=e:\windows7dev.vhd maximum=50000 type=expandable
select vdisk file=e:\windows7dev.vhd
attach vdiskexit
  • 4. You can now exit the command line and continue with the installation
  • 5. When asked which drive to install to, select the newly created disk
  • 6. You will see a warning telling you you can’t install on this disk – ignore that

22
Oct 09

SharePoint 2010 is coming to town

SharePoint 2010 Developer Center

Over the coming months I imagine there will be many posts about SharePoint 2010. Only this week there was a conference in Las Vegas for developers to get their hands dirty with it.

From a developers point of view, if you didn’t make it (like me) then the Micorosoft SharePoint 2010 Developer Center is worth a look.

There is a great introductory video here.  I’ve always been a fan of MSDN, yes occasionally there are ommisions, but for the most part it is a tremendous resource.


16
Oct 09

SharePoint Site Library Size

Background

I was recently asked to supply a breakdown of the Document Library sizes within a SharePoint Site Collection (SPSite). I had a look through the SharePoint API and couldn’t find any obvious information on the SPDocumentLibrary or SPList objects.

The first solution I came up with was to use some recursion to enumerate through each SPWeb in the Site Collection and then enumerate through each Document Library in the web, adding the file sizes in each library as I went. This approach worked but took a huge amount of time.

At previous clients, it would have been acceptable to dive into the Content Database for the site collection and write a query to do the work, unfortunately at the current site there are decent policies and rules in place to stop this from being done.

SPSite.StorageManagementInformation

By chance, I found a method on the SPSite object called StorageManagementInformation

1
2
3
4
5
6
7
8
using (SPSite site = new SPSite(url))
{
       DataTable storageInfo;
       storageInfo = site.StorageManagementInformation(
       SPSite.StorageManagementInformationType.DocumentLibrary,
       SPSite.StorageManagementSortOrder.Decreasing,
       SPSite.StorageManagementSortedOn.Size, 2000);
}

From here the data table can be queried as normal to output the information about each Document Library;

1
2
3
4
5
6
7
8
9
foreach (DataRow row in storageInfo.Rows)
{
      double size = Convert.ToDouble((row["Size"].ToString()) / 1024) / 1024;
      Console.WriteLine(string.Format("{0}/{1}\t{2}\t{3}",
                                       site.Url,
                                       row["WebUrl"].ToString(),
                                       row["Title"].ToString(),
                                       size));
}

More Information

There are several options for StorageManagementInformationType enum. Its worth noting that the row columns will be slightly different for each of them.