Fixing issue where SharePoint 2010 logs is 0 kb

by Christian Fredh 17. March 2011 03:40

This was an interesting issue I came across. All the SharePoint 2010 logs where 0 kb (commonly located at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS). It was really hard searching for error messages for the issue I was trying to fix in the first place, so I had to fix this first.

Turned out to be the account that runs the service SharePoint 2010 Tracing (SPTraceV4) that didn't have the correct permissions. Someone had probably messed with the service accounts. Here is how to fix it on Windows Server 2008 R2:

  1. Go to Start menu -> Administrative Tools -> Services
  2. Right-click on the SharePoint 2010 Tracing service and then click Properties
  3. Note the service account that runs the serivce under the tab Log On and then close the Properties window
  4. Go to Start menu -> Right-click Computer -> Manage
  5. Navigate to Configuration -> Local Users and Groups -> Groups
  6. Locate the group Performance Log Users -> Right-click and then click Properties
  7. Click Add... and the write or select the service account that you got in 3. and add it to the group
  8. Close the Server Manager windows
  9. Go back to the Services window and click Restart
  10. When restarted the log files should start filling up again and you can start fixing other stuff ;)


Tags: , , ,

SharePoint | SharePoint 2010

Using the ListView Control in SharePoint 2010 Beta

by Christian Fredh 24. February 2010 02:57

In SharePoint 2007 you had to modify the web.config file, manually or with a feature, to enable the ScriptManager, ListView and other features in ASP.NET 3.5.

SharePoint 2010 is built on ASP.NET 3.5 so it should just work. However, the namespace for the ListView control is not mapped in the web.config or in the SharePoint Project Item templates by default. If you do not register the the namespace you will see the "Unknown server tag 'asp:ListView'" error message if you for instance use it in a web part:


To fix it add this line to the <controls>-section under <system.web> and <pages>:

<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

Or register the namespace in the .ascx or .aspx file:

<%@ Register Assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.WebControls" TagPrefix="asp" %>

And it should work:

Hopefully they will add both before RTM.

Tags: , ,

SharePoint | SharePoint 2010

SharePoint 2010 Sandbox Solutions and Visual Studio 2010 Project Templates

by Christian Fredh 3. January 2010 19:16

Sandbox Solutions for SharePoint 2010 are great news for SharePoint development. I think we will see a lot of great features without the need of doing farm deployments. But sandboxed solutions do have their limitations and not all project templates or SharePoint Project Items (SPI) are available for sandboxed solutions.

Below are lists of the templates installed with Visual Studio 2010 Beta 2 and the availability for sandboxed solutions.

Project Templates


Name Available for sandboxed solutions
Empty SharePoint Project Yes.
Visual Web Part No. Visual Web Part template uses a user control (.ascx file) and must be deployed as a farm solution.
Sequential Workflow No. Programmatic workflows are not available for sandboxed solutions.
State Machine Workflow No. Programmatic workflows are not available for sandboxed solutions.
Business Data Connectivity Model No. BDC models is deployed at farm level and are therefore not available.
Event Receiver Yes.
List Definition Yes.
Content Type Yes.
Module Yes.
Site Definition No. Site definitions is deployed at farm level and are not available.
Import Reusable Workflow No. Programmatic workflows are not available for sandboxed solutions.
Import SharePoint Solution Package Yes, if the items that is imported from the package are supported.

SharePoint Project Items


Name Available for sandboxed solutions
Visual Web Part No. Visual Web Part template uses a user control (.ascx file) and are not available for sandboxed solutions.
Web Part Yes.
Sequential Workflow No. Programmatic workflows are not available for sandboxed solutions.
State Machine Workflow No. Programmatic workflows are not available for sandboxed solutions.
Workflow Association Form No. Association forms includes .aspx files and are not available for sandboxed solutions.
Workflow Initiation Form No. Initiation forms includes .aspx files and are not available for sandboxed solutions.
Business Data Connectivity Model No. BDC models is deployed at farm level and are therefore not available.
Application Page No. Application pages includes .aspx files and are not available for sandboxed solutions. Nothing under the Layouts folder can be deployed in sandboxed solutions.
Event Receiver Yes.
Module Yes.
Content Type Yes.
List Definition From Content Type Yes.
List Definition Yes.
List Instance Yes.
Empty Element Yes.
User Control No. User controls includes .ascx files and are not available for sandboxed solutions. Nothing under the ControlTemplates folder can be deployed in sandboxed solutions.

More information about sandboxed solutions:

SPWeb.EnsureUser with elevated privileges

by Christian Fredh 3. January 2010 00:07

When you work with groups and users and custom code in SharePoint you often use the SPWeb.EnsureUser method that according to MSDN documentation “checks whether the specified login name belongs to a valid user of the Web site, and if the login name does not already exist, adds it to the Web site”. The method returns an SPUser object.

The user who runs this method needs to be a site collection administrator and the user or group to resolve needs to come from an Active Directory source.

An alternative is to use SPWeb.SiteUsers[loginName] that also returns an SPUser object without requiring site collection administrator privileges. The issue you run into with using this property is that if the user haven’t logged in yet, the user will not be found, and that is why you want to use the EnsureUser method. But again, you need elevated privileges for this. EnsureUser actually uses the SiteUsers property for returning the user after adding it if needed.

Created a helper method for this purpose, that you might find helpful if working with users from the SharePoint object model. It is written as an extension method for the SPWeb class. It can easily be converted to a regular static method if not using C# 3.0 for SharePoint 2007 development.

public static class SPWebExtensions
    public static SPUser EnsureUserElevated(this SPWeb web, string loginName)
        if (web == null)
            throw new ArgumentNullException("web");

        if (string.IsNullOrEmpty(loginName))
            throw new ArgumentException("Login name cannot be null or empty.", "loginName");

        using (SPSite elevatedSite = new SPSite(web.Site.ID, web.Site.SystemAccount.UserToken))
            using (SPWeb elevatedWeb = elevatedSite.OpenWeb(web.ID))
                // Allow unsafe updates required, throws exception without, if not administrator.
                elevatedWeb.AllowUnsafeUpdates = true;

        return web.SiteUsers[loginName];

As you can see the SiteUsers property is still used to return the user, to get the correct user context, if you afterwards use SPUser.ParentWeb.CurrentUser for example.

Here is how you would retrieve a user using the method:

string loginName = "SOMEDOMAIN\someLoginName";
SPUser user = SPContext.Current.Web.EnsureUserElevated(loginName);

Tags: , , , ,

.NET | .NET 3.5 | SharePoint | SharePoint 2007

Rename and Number Pictures with PowerShell

by Christian Fredh 9. November 2009 04:46

I had a problem. I had all these pictures taken from my recent journeys. When copying them over to my computer, they all had obscure file names like IMG_343.NEF. They were in raw format (.NEF) so the otherwise nice Windows feature of importing pictures didn’t recognize them, and the camera program didn’t have a fast way renaming them.

So, I thought: Let’s try to solve it with PowerShell, felt that I needed to play around with PowerShell anyway. Thought I share the script I used. It could definitely be used with other files as well, but I think pictures is the most common files to apply it to.

Please, be aware that I’m not a PowerShell expert, I’m not responsible of what happens to your files, and take backup of your files before using it.


Get-ChildItem | Sort-Object CreationTime | %{$suffixNumber=1} { %{$suffixString="{0:D3}" -f $suffixNumber} 
{ Rename-Item $_ -NewName "Las Vegas $suffixString.nef" ; $suffixNumber++ } }

The Get-ChildItem cmdlet gets all files in the folder you are in, and then we are piping the results to Sort-Object which sorts the files by creation date, and then for each file, we are renaming it and then increasing the number we are adding to the file name. I read the article Renaming Files by Jeffrey Snover to help me with this.

Change the $suffixNumber=1 if you want it to start from 0 or some other number. The $suffixString="{0:D3}" -f $suffixNumber is formatting the number to include leading zeros if nessesary. You can change the number 3 if you want more or less leading zeros. I read the article Windows PowerShell Tip of the Week - Formatting Numbers to help me with this. And, of course, change "Las Vegas " to what ever makes sense to your case.

The result was files with nice looking file names, Las Vegas 001.nef, Las Vegas 002.nef, Las Vegas 003.nef and so on.


Tags: , ,


SharePoint 2010 Development Environment Options

by Christian Fredh 4. November 2009 08:25

Great news for developers targeting SharePoint 2010 at the SharePoint Conference 2009. Many exiting features and tools, one of them being that SharePoint 2010 is installable on Windows 7 (and Vista), which means that SharePoint development is now supported on the client. This is a huge deal, since SharePoint development becomes more mainstream and easier to get started with.

Having SharePoint installed on the client is also good for demos. It is not supported for production environments.

Since SharePoint 2010 only support 64-bit operating system, this also applies if installing on Windows 7, you have to have the 64-bit versions. Since Windows Virtual PC doesn’t support 64-bit operating systems and Microsoft Virtual PC 2007 cannot be installed on Windows 7, using VPC is no longer an option – which is a good thing.

Basically, you are down to three different options when developing on the client, all with pros and cons.

On the Metal

SharePoint installed on your regular Windows 7 environment.


  • You can use all the hardware on your computer with no additional work, including networking. This means better performance and fewer problems with VPN connections.
  • You can use your other applications like Outlook and browsers at the same time with convenience.
  • You can start up SharePoint when developing and shut it down again when not using it, with simple PowerShell scripts. I will provide this scripts as a separate blog post.


  • If you are like me, switching between different projects a lot, it might take some thought to set them up on the same environment. Writing PowerShell scripts to set up environment and data for different projects could probably help with this.
  • If the SharePoint install gets messed up, it might take some time to solve, although I think it will be a lot easier in this version.

Bootable VHD

In Windows 7 you set up a bootable virtual hard drive with the SharePoint environment. When the computer is booting up, you choose to boot from the VHD where SharePoint is installed.


  • You can use all the hardware on your computer with no additional work, including networking. This means better performance and fewer problems with VPN connections.
  • You cannot use different VHDs for different projects with ease.
  • If you need a fresh install, just throw the VHD away and replace it with a backup with the fresh install.


  • You cannot use your regular applications when developing, and a restart is needed if you would like to switch to your regular environment. Of course, you can install as many applications as you which on the VHD, but it would need some work to keep it synchronized if that is preferable.


Using Windows Server 2008 R2 with Hyper-V on VHD, or if you use it as your base operating system, and then set up the SharePoint environment on one or more VHDs with Hyper-V.


  • Supports advanced scenarios with multiple servers and environments.
  • Your tests will be run in a realistic environment.


  • Takes time to set up, especially if your not used to Hyper-V.
  • As with the bootable VHD options you are not in your regular environment and don’t have your regular applications available. If you use Hyper-V to run your regular environment you would be able to switch faster, but that is probably not a common scenario.

Personally, I will try to use the On the Metal option, because I think it’s such a huge win to be able to work in your regular environment, and try to solve issues with different projects and SharePoint installment issues with PowerShell scripts, for setting up project environment and resetting the installation.

In later posts I will dig deeper on how to set up these environments.

Tags: , ,

SharePoint | SharePoint 2010

The Enumerable Class – Range, Repeat and Empty

by Christian Fredh 3. October 2009 19:36

The Enumerable class was introduced in .NET 3.5 and lives in the System.Linq namespace and provides the LINQ extension methods. It also has three static methods that can be really useful, Range, Repeat and Empty that all returns a generic IEnumerable.


The Range method provides a quick way of getting a sequence of integers in a specified range. Instead of writing something like this to get a collection of integers:

static IEnumerable GetSequence(int start, int count)
    List sequence = new List();
    for (int i = start; i < start + count; i++)

    return sequence;


static IEnumerable<int> GetSequence(int start, int count)
    for (int i = start; i < start + count; i++)
        yield return i;

and call the method with:

IEnumerable<int> sequence = GetSequence(1, 100);

you could just write:

IEnumerable<int> sequence = Enumerable.Range(1, 100);


The Repeat method provides a quick way of getting a collection of one repeated value. Instead of writing something like this:

static IEnumerable<T> GetSequence<T>(T value, int count)
    for (int i = 0; i < count; i++)
        yield return value;

and call the method with:

IEnumerable<string> sequence = GetSequence<string>("My Repeat Value", 10);

you could just write:

IEnumerable<string> sequence = Enumerable.Repeat<string>("My Repeat Value", 10);


Ever wanted to get or return an empty collection? I know I have. Until I found this method I have used things like:

return new int[] {};


return new List<int>();

or in some situations:

yield break;

Using yield break has a major drawback that it cannot be used in catch blocks as described by Eric Lippert.

But the Empty method provides a clear and descriptive way of getting an empty collection of any type. Just write:

return Enumerable.Empty<int>();

Tags: , ,

.NET | .NET 3.5 | LINQ

Powered by BlogEngine.NET
Theme by Mads Kristensen

About Christian Fredh

Christian Fredh

A twenty six year old solutions architect and developer living in Stockholm, Sweden. I work as a SharePoint consultant at Avega Group with .NET and SharePoint development.


The opinions expressed herein are my own personal opinions and do not represent my employer's view. Use the information on this site at your own risk.


Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

© Copyright 2009, Christian Fredh.