Impersonating Any User On SharePoint

When a SharePoint web part, or similar custom code, is running on SharePoint the active SPContext will either be impersonating the current user’s account or the guest account (if enabled). This means that all of SharePoint’s security is maintained when accessing lists, items, etc. However; there may be some instances when you want the custom code to be able to access items (or lists, etc.) which the current user does not have access to without actually giving the user direct access to these particular items. Fortunately, this is a pretty easy task to achieve and can be accomplished in a number of ways.

Method 1. Using elevated security

This method takes advantage of the Microsoft.SharePoint.SPSecurity static helper methods, in particular, the RunWithElevatedPrivileges method. The objective of this method is to execute code with full control regardless of the users delegated roles. Example:

SPSecurity.RunWithElevatedPrivileges(() => {
    // Code running with full control

The most important thing to note here is that any SharePoint context objects that have already been instantiated outside of the elevated security blocks do not have full control, even if referenced from within the elevated security blocks. This means that you can not simply call SPSecurity.RunWithElevatedPrivileges(() => SPContext.Current.ListItem.Delete()); and expect it to work if the current user does not have permission to the delete the current list item; instead, you must instantiate a new SPSite object within the elevated security blocks and then delete the list item. For example:

SPSecurity.RunWithElevatedPrivileges(() =>
    using (SPSite site = new SPSite(SPContext.Current.Site.ID))
        using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
            SPList list = web.Lists[SPContext.Current.List.ID];
            SPListItem item = list.Items[SPContext.Current.ListItem.UniqueId];

Now when the above code runs, it should not have any problems deleting the current list item, even if the current user does not have permission to delete the item.

Method 2. Impersonating another user

This is another simple method which involves instantiating a new SPSite object running under a different context to that of the invoking users’ context. To achieve this, when we are instantiating the new SPSite object, we simply pass in the SPUserToken of the user we wish to impersonate. For example, we could run under the system account:

using (SPSite site = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.SystemAccount.UserToken))
    // code here

The thing to note with this method is that the user being impersonated needs to have permission to perform the actions specified.

The UserToken is available from SPUser objects. So before creating the new SPSite object, you would need to find the user object for the user you wish to impersonate, or otherwise, have some way of reference the user’s token.

Adobe, Stop Killing My Internets!

I am not sure if it just me, but lately it seems that Adobe Flash Player is becoming more and more unreliable, and causing my web browser (be it Chrome, FireFox and/or, I.E. — I prefer Chrome, although I wish it supported ICC profiles like FireFox) to constantly crash.

As Adobe Flash is widely used it, unfortunately, is not practical to completely remove it from your machine; however, there are a few simple tools which let you automatically block Flash from loading unless you white-list the site or click on the flash to play it. This technique is also great for preventing those annoying Flash ads that pop up in your face (Although some of them do look pretty cool)!


There are a few extensions available for Chrome; if you do a quick search for “flash block” or just “flash” on the Google Chrome Extensions website you’ll be sure to find plenty of them.

The extension I use is called FlashBlock, and it does just that. When you visit a website all of the flash elements will not render; instead, they will be replaced by a flash icon placeholder. If you click on the placeholder that (and only that) flash object will load as normal. You can also right-click the placeholder and temporarily allow all flash content on the page to load.  Additionally, the extension places an icon at the end of the address bar which shows if the current site is ‘allowed’ to display flash content or if it is blocked. It also lets you click on the icon and add the site to the flash white-list or remove it from the white-list.


Similar to Google Chrome’s extensions, is Firefox’s support of add-ons — many of which are related to blocking flash, among other, content. A search of the Add-ons for Firefox website will reveal a number of options available. A notable add-on which is aimed at blocking flash content is Flashblock, which is very similar to the Chrome Extension previously mentioned.

Internet Explorer

Download Firefox or Chrome and see above.

Method 1: Internet Explorer (IE) installs flash as an add-on — this means that you can disable it from the add-on manager. In IE click on Tools > Manage Add-ons. You should now be able to see all of you installed IE add-ons. The one you want to disable is Shockwave Flash Object. If you right-click this entry, you can then simply click disable to prevent any flash object from loading. However; to view any flash on a page, you do need to go back into this menu and enable it upon which time all of the flash objects on the page will load.

Method 2: Because IE also supports add-ons you can simply find an add-on which, as with Chrome and Firefox, disabled flash objects from loading on the page. One such extension is Toggle Flash. Toggle Flash will prevent all flash objects from loading on the page; however, it will not let you click individual flash placeholders to enable the flash content. Instead, you have to enable flash for the page, and then refresh the page to load the flash content which is just a slightly quicker version of method 1.


Download Firefox or Chrome and see above.

Gumnuts Farm Resort

Gumnuts Farm

Gumnuts Farm Resort is a horse riding resort, among many other things, situated on 140-acres in Canungra, QLD which is found in the Gold Coast hinterlands, approximately 70km south-west of Brisbane. Owned by the Webster family since 1985 the farm started as riding school for children during the school holidays and has since come to be a full-fledged farm stay, offering outback experiences for Australian and Japanese couples, families, tour groups, school camps, and holidays camps.

Although the farm has quite a few activities, including cow milking, boomerang throwing, whip cracking, shooting, Cattle & Dog Shows, and 4WD tours, the main focus of the farm is the horse riding tours. The horse riding tours range from half day tours to full day rides and includes all gear required (and a horse of course). According to the Gumnuts MySpace pages the farm has approximately 25 horses at their disposal; however unfortunately when we visited we were not given appropriate horses.

During our visit we were fortunate to have been the only people staying at the farm for the weekend, another couple was supposed to be arriving but did not show. Greeted by a very friendly group of Japanese farm hands we were quick to get started with the horse riding. Having only ever ridden a horse once prior to the farm stay it was fair to say that my horse riding skills were lacking, and as such, I would have expected to have been given a fairly relaxed, calm, and slow horse which I could feel comfortable upon… this was not the case.

The horse that I had been given was named King. He is a standardbred Gelding, with a stubborn nature and scares easily. The ride started off well, with four of us trotting along the main road, but then King decided he had had enough and decided to turn around to go back home. After some persuasion, he turned back around on the track and continued on our journey… that is until a car passed us, giving King a fright, sending him into a gallop. Luckily I was able to quickly bring him to a quick stop (before being thrown off). This was the first, but not last time this occurred. In the end, we decided that it would be best just to turn around and go back to the farm.

After arriving back at the farm we proceeded with the rest of the activities on our schedule; milking the cow, boomerang throwing, whip cracking, and shooting. The friendly staff were kind enough to let us take our time and enjoy each of the activities at our own leisure. Included in the farm stay were 3 meals (lunch, dinner, and breakfast) which were nothing fancy, but edible meals cooked by the farm hands. During the evening, after having completed all of the activities we had free roam of the farm, taking in the beautiful areas and getting some nice photos during sunset.

A great bonus of the farm is that it is extremely close to O’Reilly’s in Lamington National Park, for a significantly cheaper price than staying at the O’Reilly resort. All in all Gumnuts Farm Resort is a cheap and fun way to get back in touch with nature but is more suited for larger tourist groups then a couples/family getaway.

See Additional Photos From Gumnuts Farm Resort.

Unable To Instantiate TRIM Database: 80040154

I recently came across this error while attempting to connect to TRIM 6 R2 via the TRIMSDKRetrieving the COM class factory for component with CLSID {8A354548-6BCB-11D3-B273-00A0C9FC3DC0} failed due to the following error: 80040154.

This was a little alarming because it was using the same data adapter as a few other TRIM projects, which were working fine; the only difference between the project was that this particular project was a WPF application, and all of the other applications were ASP.NET applications. This particular application had also previously worked fine, the only change was that I had been upgraded to a 64-bit environment.

After a bit of playing around and research, I discovered the TRIM SDK will not connect under a 64-bit process.


  1. In Visual Studio, right-click your project and go to Properties (last item).
  2. Select the Build tab.
  3. Change the Configuration option to All Configurations.
  4. Change the Platform Target to x86.

This will ensure that your application will only run under an x86 architecture, and will be able to connect to TRIM even on a 64-bit host.

Looking at the QuickSpecs for TRIM 7 it is being based on a 64-bit architecture and therefore this issue should be eliminated come TRIM 7 (in addition to some SDK enhancements and UI integration tools).

Oracle 06413: Connection Not Open (x64)

Having changed to a 64-bit development machine at work recently I ran into an Oracle error while trying to generate files using CodeSmith. This error was ORA-06413: Connection Not Open. Assuming it was a connection string error, as I had not run this particular generation in some time and it was likely that the server or username/password had changed, I proceeded to test the connection from SQL Developer. Success!

After ruling out that the connection was indeed valid I did a quick Google search for the error message. After a few clicks I discovered a very well known (has been around for a few years) Oracle issue; When executing an Oracle command from an application with parentheses or equals — ‘(‘ or ’)’ or ‘=’ — in the path than the specified error message is thrown.

In this particular case, CodeSmith had been installed under C:/Program Files (x86)/CodeSmith which was causing Oracle to fail. The quickest workaround was to simply move CodeSmith from the Program Files (x86) path e.g. into C:/CodeSmith. However; there is a patch (5383042) for Oracle 10g, which is also applied to Oracle 11G.

Australian Internet Filter: What Can I Do?

What is it?

The Australian Federal Government is introducing a mandatory ISP-level filtering of all Refused Classification (RC) rated content. This means all websites (or part thereof) which have been refused classification under Australia’s classification laws will be blacklisted.

See the Electronic Frontiers Open Internet website for more information.

What can I do?

The simplest thing you can do is sign the EFA’s online petition.

Additionally, you can contact your local member of parliament or contact Senator Conroy, the Minister for Broadband, Communications and the Digital Economy.

Take Action!

iiNet Vs AFACT: The Verdict

As a lot of people are probably already aware iiNet was taken to court by the Australian Federation Against Copyright Theft (AFACT) for allegedly allowing its customers to illegally download copyrighted material (e.g. movies, music, etc).

This morning Justice Cowdroy has ruled in favour of iiNet stating that “I find that iiNet simply can’t be seen as approving infringement”. His verdict was that the “copyright (infringement) occurred as result of use of BitTorrent, not the Internet” and that “iiNet has no control over (the) BitTorrent system and (is) not responsible for (the) BitTorrent system.”

Common sense and Australia’s Internet Freedom prevails, for now (see mandatory Australia Internet Censoring).

Win 7 Live Messenger Task Bar Fix

For those of you ‘lucky’ enough to have already updated to the new Windows 7 then you have probably already noticed the major changes to the task bar. Good or bad, you decide. Personally, I like some of the new functionality that it provides but I also enjoy a slim taskbar — similar to that of Vista. Fortunately, Microsoft provided a “Use small icons” option in the taskbar properties (right-click the taskbar and select properties) which makes the task bar a similar size to that of Vista.

Changing the taskbar to use small icons, however, does not fix the fact that Windows Live Messenger likes to constantly take up space in the taskbar even when the window is not open. Since there does not currently appear to be an option in Windows Live Messenger to display the program in the system tray, instead of on the taskbar, we need to use a simple work around.

First, close any current Windows Live Messenger instances. Then open your start menu and locate the Windows Live Messenger shortcut. Right-click the shortcut and select Properties. Switch to the Compatibility tab and check “Run this program in compatibility mode for:” and select Window Vista (Service Pack 2)”. Now start Windows Live Messenger and problem solved. You should now see the Windows Live Messenger icon in the system tray. As you would on Vista, XP, etc.