Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to invoke SkyDrive Pro's "Sync a new library" dialog from a webpage via the "grvopen" URI scheme

Context

SkyDrive Pro lets you sync SharePoint libraries offline.

I wanted a way to give users a single click button to sync a particular library.

You can do this via an old Groove ActiveX control, but that's horrible and I couldn't make it work anyway.

You can also do this via a special URI, but the format is a bit special and not documented anywhere.

The Answer

For this document library:

https://sp.mycompany.com/sites/foo/bar

This is the URI to invoke SkyDrive Pro:

grvopen://https_58_47_47sp_46mycompany_46com_47sites_47foo_47bar/00000000_450000_450000_450000_45000000000000/101?OPENLIST

Just put that in a normal anchor tag:

<a href="grvopen://https_58_47_47sp_46mycompany_46com_47sites_47foo_47bar/00000000_450000_450000_450000_45000000000000/101?OPENLIST">Take this offline with you</a>

The Detail

The format is:

grvopen://uri/guid/type?OPENLIST

Those three components use a (custom?) encoding. The algorithm is in the attached C# file.

The URI is that of the document library you want to sync.

I'm guessing that the GUID is meant to be to library ID, but it doesn’t seem to care as long as you supply enough blank digits. (And encode it too.)

Type is the value from SPListTemplateType. For example, 101 is SPListTemplateType.DocumentLibrary.

On a machine with SkyDrive Pro installed, invoking one of these grvopen-based links will launch something like C:\PROGRA~1\MICROS~1\Office15\GROOVE.EXE /TakeOffline: "%1", based on the value of HKEY_CLASSES_ROOT\grvOpen\shell\open\command.

Uri BuildGrooveUri(Uri libraryUri)
{
const string grooveOpenUriTemplate = "grvopen://{0}/{1}/101?OPENLIST";
var uri = string.Format(
grooveOpenUriTemplate,
Encode(libraryUri.AbsoluteUri),
Encode(Guid.Empty.ToString())
);
return new Uri(uri);
}
string Encode(string plain)
{
return plain
.ToCharArray()
.Select(c => char.IsLetterOrDigit(c) ? c.ToString() : "_" + ((int)c).ToString())
.Aggregate("", (s, c) => s + c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment