SPC366 Making SharePoint Websites Sing on your Smartphone

Well that was fun!

I had a real blast co-presesnting that session with Chris. As promised I have a bunch of resources for you to download and peruse.

Disabling Mobile Re-direction via PowerShell

Hmmm, apparently WordPress won’t let me host any useful file formats in my site (not even plain .txt files!!!) so sorry…. My plans of giving you folks full Visual Studio solutions as zip files has been foiled! I’ll work out a cunning plan to get around this later.

In the meantime:

The custom re-director I showed off was based off this MSDN article: http://msdn.microsoft.com/en-us/library/ms441925.aspx. Essentially you should:

  • Create a mapped folder in you SharePoint Solution, mapping it to 14HIVE\TEMPLATE\LAYOUTS\MOBILE
  • Into this add your own custom aspx page that inherits from Microsoft.SharePoint.MobileRedirection.SPMobilePage
  • Override the OnInit method to provide your custom redirection
  • Create a copy of the existing mbllists.aspx as mbllists.old.aspx, or similar
  • Replace the existing mbllists.aspx with your own custom page that contains:
  • <SPMobile:SPMobileForm RunAt="Server" PageType="HomePage" Paginate="true">
    	<SPMobile:SPMobileHomePageRedirection ID="SPMobileHomePageRedirection1" RunAt="Server" 
        PageFileName="CustomMobileRedirect.aspx" />
    </SPMobile:SPMobileForm>
    

  • Deploy the solution

The HttpHandler that I used to trick SharePoint into not re-directing I sourced from the blog of Waldek Mastykarz: http://blog.mastykarz.nl/inconvenient-sharepoint-2010-mobile-redirect/.

I then coupled it with a really simple webpart that contained the following code.

using System;
using System.ComponentModel;
using System.Web.UI.WebControls.WebParts;

namespace VariationsRedirector.RedirectWebPart
{
    [ToolboxItemAttribute(false)]
    public class RedirectWebPart : WebPart
    {
        protected override void OnInit(EventArgs e)
        {
            if (Page.Request.Browser.IsMobileDevice)
            {
                string mobileUrl = GetMobileSiteUrl();
                Page.Response.Redirect(mobileUrl);
            }
            base.OnInit(e);
        }

        /// <summary>
        /// Gets the Mobile URL form the config settings list if it exists
        /// </summary>
        /// <returns>The mobile URL</returns>
        private string GetMobileSiteUrl()
        {
            //This is just hard coded to change the URL of the current request,
            //swaping the mobile variation label for the www variation label, 
            //hey, it's demo code...
            string mobileUrl = Page.Request.Url.ToString().ToLower().Replace("/www/", "/mobile/");
            return mobileUrl;
        }
    }
}

Many thanks to the Conference team for allowing me to present and to all of you that came along to my session
Feel free to reach out to either Chris of myself if you have any further queries :)

Posted in Uncategorized | 1 Comment

Visual Web Parts for SharePoint in the Sandbox

Get ‘em while they’re hot! Visual Studio 2010 SharePoint Power Tools plus a sandboxed compilation to ensure you’re not accidentally calling outside of the allowed set of types and members.

Posted in Deployment, Development, Sandbox, SharePoint, Visual Studio | Leave a comment

SPServices Helper Function: Resolve the Guid of a View

If you’re using the excellent SPServices library to wrap up access to the SharePoint web services from JavaScript, good stuff!
If, like me, you want to query a View on a given list you’ll need to pass the Guid of the view as the viewName parameter. Using the display name will give you the error: Parameter viewName is missing or invalid. 0×82000001

To resolve this you’ll need to call the GetViewCollection method for a given list and then parse the result to find your Guid. I’m a total newbie to jQuery and client side scripting so I found this a little tricky to get right, but I got there. So, here’s a helper for you use:

function ResolveListGuidFromName(webUrl, listName, viewName){
	var guid;
	var filter = "View[DisplayName='"+ viewName +"']";
	$().SPServices({
	    operation: "GetViewCollection",
	    async: false,
	    webURL: webUrl,
	    listName: "Votes",
	    completefunc:function (xData, Status) {
			guid = $(xData.responseXML).find(filter).attr("Name");
		}
	});
	return guid;
}

Not too bad for my first hack at this stuff.

Posted in Development, jQuery, SharePoint, SPServices | 5 Comments

TFS 2010: Add to security groups from outside of the current domain

If you’re a SharePoint developer like me, chances are that the dev server you’re working on is joined to a different domain from your corporate identity. Now this makes it tricky to add users to your TFS Security Groups from inside of Visual Studio as you can’t browse the AD users on your corporate domain

Thankfully there is a handy command line tool that you can use called TFSSecurity.exe, by default you can find it in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

What you need to run is:

TFSSecurity.exe /collection:http://<serverUri>:<port>/<virtualDirectory>/<collectionName>/g+ “[<projectName>]\<group>” n:”<DOMAIN>\<user>”

Replace everything in angle brackets with the values that match your environment. As a rule of thumb for default install the virtual directory is tfs, the port is 8080 and the collection is default. So to add INTERGEN\Gavinb to project Awesome as a contributor the command looks like this:

TFSSecurity.exe /collection:http://tfsserver:8080/tfs/default /g+ “[Awesome]\Contributors” n:”INTERGEN\gavinb”

Posted in Security, TFS, Visual Studio | Leave a comment

Office 365 and Passwords

Today I learned that the new password policy for Office 365 specifies an upper limit on password length.

Yes, that’s right folks, some special person decided that passwords for Office 365, and therefore Exchange Online, should be 8-16 characters in length. As for why I have no idea.

Personally I think an upper limit on password length is retarded. I currently use a password scheme based on a short meaningful phrase which often results in passwords of over 16 characters.

According to my friend in our IT services team this limitation is not in place for those people who are using ADFS, so I guess the takeout here is ADFS is good, and as far as Office 365 goes, you can be “too secure”

Posted in Security, WTF | Leave a comment

SPEasy Setup Scripts: Gotcha!

A workmate of mine just recently used the SharePoint Easy Setup Script to setup a Windows 7 machine for SharePoint development. Upon trying to browse newly created Web Applications with host headers he was prompted to authenticate but these authentication attempts always resulted in a 401.1 error.

It turns out that the easy setup scripts don’t disable the loopback check. Luckily that has a well documented and easy fix which can also be done via PowerShell.

Posted in Development, SharePoint | Leave a comment

Serving HTML5 Video from SharePoint Document Libraries

So you want to serve up some video content and use the <video> tag? Cool!

You want to do it using video files you have in SharePoint? Cool, that shouldn’t be too hard.

Unfortunately out of the box SharePoint 2010 is going to serve that video file out of the document library with a MIME Type of application/octet-stream, which IE and Firefox are not going to recognise as playable video. Chrome seems to be inspecting the file and determining the file type itself so video plays in that browser without needing a correct MIME Type sent from the web server.

I’m not going to get deeply into the ins and outs of the codec nightmare (ugh). Expect to say, there are some good free tools for encoding your video as H.264. I like x264 for a command line tool or H.264 Encoderif you want a GUI. I’m not discussing WebM as I didn’t need to create videos using that encoding for the piece of work that generated this blog post.

If you’re after a hand on the front of generating your HTML, check out Video for Everybody. One of my big complaints is that there is nothing laid down in the spec to require a “full window” mode control, the individual browsers may provide this control, but at this stage IE, Firefox and Chrome don’t . If you’re looking to provide something on this front, then I’d suggest using VideoJS

So assuming that you have that all sorted there are a couple of steps to make SharePoint serve the content in a manner that a browser can use, so don’t just stand there, let’s get to it.

Step 1 – Configure IIS 7 to provide a MIME type for .mp4 files.

Yes, I’m only covering the .mp4/H.264 case, just repeat Step 1 tweaking for WebM/Ogv

1. From the Start menu, enter inetmgr in the search box and press Enter. An instance of the IIS Management Console will start.

2. Select the server node, in the Features View locate the MIME Types feature in the IIS Group and double click on it.

MIME Type in IIS7

3. In the Actions pane click Add…

4. Fill in the form providing .mp4 as the File name extension and video/mp4as the MIME Type and click OK

Add MIME Type

5. Close the IIS Management Console.

Step 2 – Configure the SharePoint Web Application to serve mp4 using the configured MIME Type.

1. From the Start Menu, select All Programs | Microsoft SharePoint 2010 Products | SharePoint 2010 Central Administration. Under Application Management select Manage web applications.

2. Select the desired web application in the list.

3. Click on General Settingsin the ribbon.

4. Scroll down and find the Browser File Handling section, change the selection to Permissive, scroll to the bottom of the dialog and click OK.

Browser File Handling

5. Close the browser window.

6. You now need to reset IIS. Open and command prompt and enter run the iisresetcommand.

BOOM!

You’re now serving video files in a manner that all the major browsers should be able to play them when used as a <source> element in the <video> tag!

Posted in Configuration, Development, HTML5, SharePoint | 2 Comments

Hey where is my <video>?

So, I’m running Windows Server 2008 R2 aka Win7 Server. I installed IE 9 but none of the videos on the Video Format Support Page are playing?

WTF? That page is from Microsoft to show off the HTML5 support in IE9.

Turns out that I’m missing the codecs for H.264 and AAC which are bundled in the Desktop Experience feature, which, on Server 2008 R2 is missing these codecs.

Easy fix though, Microsoft have an update for the Desktop Experience on Server 2008 R2, download, install and you’re laughing at silly HTML5 videos Smile

Posted in HTML5, WTF | Leave a comment

SharePoint 2010 SP1 is out, but wait there’s more!

So SharePoint 2010 Service Pack 1 is available for Download.

The SharePoint team are also shipping a June 2011 CU with a bunch of fixes that didn’t get into SP1 and it’s “ strongly recommended to install the June 2011 Cumulative Update immediately after the installation of Service Pack 1.”

More detail over on the SharePoint blog: http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?pID=984

Also included are a few FAQs.

So, what’s in SP1?: Check out Andrew Connell’s post about What’s New In Service Pack 1, this of course is additional to all the hot fixes and previous CUs that are bundled into the service pack.

Posted in Maintenance, Service Pack, SharePoint, SP1 | Leave a comment

Running SharePoint Timer Jobs from PowerShell

From time to time you need to execute a given SharePoint timer job now. Sure you could go into Central Admin, find it and run it manually, but where’s the fun in that? Plus sometimes you need to automate this, say in an install scenario.

Luckily it’s dead easy using the SharePoint cmdlets

Heck you can do it in a couple of lines with some pipelining.

$WebApp = Get-SPWebApplication http://mywebappurl
$job = Get-SPTimerJob | ?{$_.Name -match $JobName} | ?{$_.Parent -eq $WebApp}

Or if you’d like to be a bit more robust and re-usable:

function StartJobOnWebApp
{
	param([Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
    [Microsoft.SharePoint.PowerShell.SPWebApplicationPipeBind]
    $WebApplication,
	[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=1)]
	[string] $JobName)
	process
	{
		$WebApp = $WebApplication.Read() 
		$job = Get-SPTimerJob | ?{$_.Name -match $JobName} | ?{$_.Parent -eq $WebApp} 
		if($null -ne $job)
		{
			Write-Host -ForegroundColor Yellow "Starting "$job.DisplayName
			Start-SPTimerJob $job
		}
	}
}

Posted in PowerShell, SharePoint, Timer Jobs | 2 Comments