Microsoft


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

3
Nov 09

Microsoft File Transfer Manager: Trying to Connect

Background

I currently have an MSDN subscription and found a need to download some software for a project. Every time I started FTM, the download would say “Interrupted” and the status “Trying to Connect”.

Searching the Internet provided lots of disgruntled posts about FTM, but none that helped.

Solution

This is probably an issue local to my pc/network; but if it helps anyone else, it’s a bonus.

To get it working, I needed to restrict the protocols available for transfer to HTTP. With HTTPS selected, it didn’t work. This may be my over zealous firewall configuration or it may be an issue, but it’s fixed for me now.

ftm


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.


21
Oct 09

Outlook 2007 Add-ins

Where the heck are they?

I’ve been doing a lot of on an Outlook Add-in (to be blogged later) which will use the Graphing previously mentioned. The problem is, when you build and run the Add-in, it’s put into Outlook in such a way that it’s there long after you’ve finished debugging.

In other Office 2007 products I’ve found it easy to track them down, but Outlook wasn’t so easy…..

Even if it helps one person, here’s the process to remove your work in progress add-ins

  1. ToolsTrust Center…
  2. On the left hand navigation bar select Add-ins
  3. At the bottom of the right hand pane, select COM Add-ins from the drop down box, then press Go
  4. Find the Add-in that you want to remove and select it
  5. Press the Remove button
  6. Press OK

Job done.

It’s entirely possible that everyone else knew where it was except me…. and now I do to! :)


20
Oct 09

.NET Graphs

Background

This is not going to be a comprehensive blog post to start with, however I think it will become a subject that sits as a regular fixture on this blog. I’ve recently been looking at how to graph data, something I became interested some years ago when I saw a SVG diagram of a network map.

There are several projects I am working on that require some kind of network digram to be displayed specific to the problem domain I’m working in.

QuickGraph

Codeplex has a project that can be used to create the data graphs that will be used to generate the visualisation. Rather that talk about the usage too much here, I’d strongly recommend that you use the excellent documentation available from this site;

http://www.codeplex.com/quickgraph/

My example was created using peoples names and the links they represented within a family.

Essentially, it’s simply a case of adding the people as vertices and their connections as edges. This will represent the data graph.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Create the graph
var graph = new AdjacencyGraph<string, SEdge<string>>();
 
// Add Vertices - These are the people
graph.AddVertex("Owen");
graph.AddVertex("Dan");
graph.AddVertex("Stephanie");
graph.AddVertex("George");
graph.AddVertex("Alex");
graph.AddVertex("Megan");
 
// Add the Edges - These are the links between the people
graph.AddEdge(new SEdge("Owen", "Dan"));
graph.AddEdge(new SEdge("Owen", "Alex"));
graph.AddEdge(new SEdge("Owen", "Megan"));
graph.AddEdge(new SEdge("Megan", "Dan"));
graph.AddEdge(new SEdge("Alex", "Dan"));
graph.AddEdge(new SEdge("Owen", "Stephanie"));
graph.AddEdge(new SEdge("Owen", "George"));
graph.AddEdge(new SEdge("Stephanie", "George"));
graph.AddEdge(new SEdge("Alex", "Megan"));

Microsoft GLEE

GLEE is a research project from Microsoft that has since become a commercial product call Microsoft Automatic Graph Layout (MSAGL). GLEE is still available for download, however this may change.

Download Microsoft GLEE

A GleeGraph Populator is required to fill the GLEE Graph with the vertices from my QuickGraph data graph.

At this point, I should say that it may be the case for this example that I don’t need to use QuickGraph, I’ll update as I learn more on this subject.

Once a the graph populator has been computed, the graph visualisation can be displayed in the GLEE control using the ShowDialog method of GleeGraphExtensions.

1
2
3
4
5
6
7
8
9
// Create the GleeGraph Populator
var gleeGraphPopulator = GleeGraphExtensions.CreateGleePopulator<string, SEdge<string>>(graph);
gleeGraphPopulator.Compute();
 
// Create the actual Graph from the poulater
Graph renderGraph = gleeGraphPopulator.GleeGraph;
 
// First attempt to Display graph
GleeGraphExtensions.ShowDialog(renderGraph);

The end result is shown below, the representation of the vertices and edges can be modified, I’ll be learning about this along the way and will do further posts.

Output from Microsoft GLEE

Output from Microsoft GLEE

As can be seen from this image, you can zoom and drag the graph around. It can also be printed or saved to an image.

Watch this space….

<pre

dlang=”csharp”>

// Create the graph
var graph = new AdjacencyGraph<string, SEdge<string>>();
// Add Vertices – These are the people
graph.AddVertex(“Owen”);
graph.AddVertex(“Dan”);
graph.AddVertex(“Stephanie”);
graph.AddVertex(“George”);
graph.AddVertex(“Alex”);
graph.AddVertex(“Megan”);
// Add the Edges – These are the links between the people
graph.AddEdge(new SEdge<string>(“Owen”, “Dan”));
graph.AddEdge(new SEdge<string>(“Owen”, “Alex”));
graph.AddEdge(new SEdge<string>(“Owen”, “Megan”));
graph.AddEdge(new SEdge<string>(“Megan”, “Dan”));
graph.AddEdge(new SEdge<string>(“Alex”, “Dan”));
graph.AddEdge(new SEdge<string>(“Owen”, “Stephanie”));
graph.AddEdge(new SEdge<string>(“Owen”, “George”));
graph.AddEdge(new SEdge<string>(“Stephanie”, “George”));
graph.AddEdge(new SEdge<string>(“Alex”, “Megan”));
// Create the GleeGraph Populator
var gleeGraphPopulator = GleeGraphExtensions.CreateGleePopulator<string, SEdge<string>>(graph);
gleeGraphPopulator.Compute();
// Create the actual Graph from the poulater
Graph renderGraph = gleeGraphPopulator.GleeGraph;
// First attempt to Display graph
GleeGraphExtensions.ShowDialog(renderGraph);
</pre>

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.