Joel's SharePoint Architect Blog

SharePoint 2010, MOSS & WSS Tips and Consultancy Tales

Subscribe Subscribe  View Joel Jeffery's profile on LinkedIn
joelblogs.co.uk | joelj.co.uk | joeljeffery.co.uk | jfdiphoenix.co.uk

Posts Tagged ‘SharePoint 2010’

Here’s a common use case: a user in your company is complaining about how frequently they receive Alerts from content added to SharePoint 2010 Lists.

Yes, there are quite a few tools out there, and some folks suggest using Control Point or something expensive for this requirement. But in principle you don’t need those tools.

SharePoint 2010 is best administered by PowerShell. Here’s an example script that will reset all of the alerts for a specified user (e.g. “DOMAIN\JOEL”) to receive a weekly digest.

Start-SPAssignment –Global

Get-SPWeb http://sharepoint/* | ForEach-Object { $w = $_; ForEach($alert in $w.Alerts) { if($alert.User.UserLogin -eq “domain\joel”) { $alert.AlertFrequency = “Weekly”; $alert.Update(); } } }

Stop-SPAssignment -Global

Enjoy!

Post Script:

Top tip from Andrew, one of my students. Why not train users to manage alerts for themselves? Outlook has the Manage Rules & Alerts feature to make the task easier:

Manage SharePoint Alerts from Outlook

 

Technorati Tags: PowerShell, SharePoint 2010, SharePoint 2010 Training, SharePoint Administration

Joel’s SharePoint Show On Tour!

I’ve put an events calendar showing upcoming SharePoint Show tour dates here: http://joelblogs.co.uk/tour-dates/. I’ve got 10 shows booked in between now and the end of the 2011 in the UK and Sweden, some for SharePoint Administration and some for SharePoint Development.

Drop me a line if you’re interested!

Technorati Tags: SharePoint, SharePoint 2010, SharePoint 2010 Training

SharePoint 2010 in Visual Studio 2010 has made creating Windows Workflow Foundation (WF) workflows an awful lot easier. There are still one or two areas that can be confusing to new developers

One such region of confusion surrounds the Initiation Form – the form displayed whenever a user launches your workflow, that you can use to prompt for more information required to run your workflow. Similar uncertainty surrounds the Association Form – one that is displayed whenever a list administrator attaches your workflow to their list.

Thanks to the tooling in Visual Studio, it’s now easy to add either of these forms. Right-clicking your Workflow item in Solution Explorer and choosing “Add-> New Item” will give you:

Adding a New SharePoint Item in Visual Studio 2010

Selecting either Initiation Form or Association Form will add the appropriate artefacts to your code and also configures the Element manifest of the Workflow accordingly:

Element Manifest Changes to view Initiation Forms

Let’s say we wanted to ask the user a series of extra questions when they launch our workflow, such as their manager’s First Name, Last Name and Email Address, such that we can have access to that data within our running workflow later on.

We can now edit our new Initiation Form as an aspx page in Visual Studio. Let’s add some text boxes to capture the extra information:

image

The next question is often “how do we get this information to the workflow?” Inside the workflow itself is a SPWorkflowActivationProperties object which exposes two strings: InitiationData and AssociationData, which is respectively the data captured from the user during launch and association phases of the workflow.

The code behind for the Initiation Form has a string method called GetInitiationData(). Whatever string you return here is then available from inside your workflow using workflowProperties.InitiationData. It’s the same principle with Association Forms, GetAssociationData and AssociationData properties.

Clearly, we could go low-rent here and return a semi-colon delimited string or something naff of that ilk.

Alternatively you could store your properties temporarily in a class and then serialise that class to a string and return that. Then later in your workflow you could deserialise that back to an instance of your object.

You could put a lot of effort into this to get it really efficient, but the general principle is why not create a utility class to hold Serialise and Deserialise methods?

I’ve implemented the following candidate code using Generics to show how powerful the technique is:

public static string Serialise<T>(T item)
{
    XmlSerializer ser = new XmlSerializer(item.GetType());
    TextWriter sw = new StringWriter();
    ser.Serialize(sw, item);
    return sw.ToString();
}

public static T Deserialise<T>(string xml) where T : new()
{
    T returnObject = new T();
    XmlSerializer ser = new XmlSerializer(returnObject.GetType());
    XmlTextReader xtr = new XmlTextReader(new StringReader(xml));
    return (T)ser.Deserialize(xtr);
}

So, given a class, for example, to hold contact information:

public class Contact
{
    public string FirstName;
    public string LastName;
    public string Email;
}

You could put the following in your code behind for the Initiation Form:

// This method is called when the user clicks the button to start the workflow.
private string GetInitiationData()
{
    contact.FirstName = firstName.Text;
    contact.LastName = lastName.Text;
    contact.Email = email.Text;
    return Serialise<Contact>(contact);
}

Then in the code beside for your workflow you can get at the data again like this:

private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
    Contact contact = Deserialise<Contact>(workflowProperties.InitiationData);
    historyDescription = string.Format("Received Contact information: {0} {1} {2}",
        contact.FirstName, contact.LastName, contact.Email);
}

Hopefully this code will save you some searching and typing.

Technorati Tags: SharePoint, SharePoint 2010, SharePoint 2010 Training, SharePoint Developer

If you’re creating or editing a JavaScript file in Visual Studio and you would like some help creating Client Object Model code, you’re not alone.

It’s a little bit cryptic, but we can tell IntelliSense to include any JavaScript libraries you have on your development machine.

Simply place the following two lines at the top of your source code (watch out for line breaks!):

/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\MicrosoftAjax.js" />
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.debug.js" />
/// <reference path="C:\\Program Files\\Common Files\\Microsoft Shared\\Web Server Extensions\\14\\TEMPLATE\\LAYOUTS\\SP.Core.debug.js" />

Then, you can get IntelliSense when you need it the most!

Enabling IntelliSense for the JavaScript Client Object Model in SharePoint 2010

Full article on MSDN available here.

Enjoy!

Technorati Tags: Development, SharePoint 2010, SharePoint 2010 Training, SharePoint Developer, SharePoint Training

Stop the Press!

The Google Maps Web Part fir SharePoint 2010 and Office 365 is now free for download complete with source on CodePlex.

Original Blog Post follows

Google Maps Web Part for SharePoint 2010Well, we’ve finally done it!

Our first product is a SharePoint 2010 Web Part that allows you to embed Google Maps in a SharePoint page.

You can use the Web Part in SharePoint Foundation, SharePoint Server (Standard and Enterprise) and even SharePoint Online (Office 365).

It lets you select a centre for the map, and then place a pushpin at a desired location. You can also add a title and label, and control the zoom level and a number of other settings. Not bad for under $20. Smile

Come and read all about our Google Maps Web Part for SharePoint 2010 at JFDI Phoenix Ltd’s web site.

Technorati Tags: Development, Mapping, Office 365, SharePoint, SharePoint 2010